
! script name: solids.d/tangentdisk
! var_topic: tangent disk to a surface at a point

!A
!A NAME:
!A
!A 	Tangent Disk		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will creates a tangent disk to a surface at a point
!A 	on the surface.
!A
!B INSTRUCTIONS:
!B
!B 	DISK RADIUS: Enter the radius of the disk.
!B
!B 	PICK SURFACE: Pick the surface the disk is to be tangent to.
!B
!B 	PICK POINT ON SURFACE: Pick the point the disk is to be tangent at.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: tangent disk ")

DIM Destination$[256]
DIM Answer$[256]
DIM Radius_var$[256]
DIM Name$[256]
DIM Element$[256]
DIM Center$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave



ActivateUndo
Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)

Units= CurrentUnits
IF Units= WsMetric THEN
        Radius= 25
ELSE
        Radius= 1
END IF


Start:!
Stat=SetInputFormat("n4=","")
Stat=SetRadiusEquals(Radius)
Radius=InputRadius("DISK RADIUS")
IF ExitScript(Destination$) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Start
        No_radius_var=0
        Stat= EntityNameCheck(C1,Radius_var$)
END IF

Intersect2:!

Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n4","")
Surface=PickEntity("PICK SURFACE ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Surface) THEN Intersect2
Stat= EntityNameCheck(Surface,Element$)
Stat=SetPickMask(WsPickNoSurf)

Pick_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("PICK POINT ON SURFACE")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(E1) THEN Pick_point
IF NOT ValidDependency(E1) THEN Pick_point
T= LastPickPara
Pick_return= CurrPickReturn
Stat= EntityNameCheck(E1,Center$)
Pc= ParameterReturnPt(E1,T,Pick_return)
Stat=SetEqualsValue(Radius)
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

Stat=SetPickMask(WsPickAll)


Stat= GenerateVarName(WsDiskSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("DISK: Tangent to surface")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,T,WsGeomCenter)
END SELECT
IF No_radius_var THEN
        V1= FreeParameter("Radius",Radius)
ELSE
        V1= FreeParameter("Radius",Radius_var$)
END IF
V2= FreeParameter("Tolerance",Tol)
Stat=Set3dInterOffset(0.0)
P1=TangentPlane(WsDiskSolidEnt,Element$,Pc,V1,V2)
Stat= NameEntity(P1,Name$)
Stat=DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(P1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("disk")
	Stat= AddItemToUndo(WsUBCreateMode,P1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Intersect2

Leave:!
stat= SetInputFormat("n4","")
Stat= SetPickMask(WsPickAll)
stat= DeleteEntity(Pt)
IF (NOT LEN(Destination$)) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
