
! script name: solids.d/tangentdisk
! 3dtopic: tangent disk to a surface

!A
!A NAME:
!A
!A 	Disk: Tangent
!A
!A DESCRIPTION:
!A
!A 	This script will create a disk tangent to a surface, at a point on
!A 	the surface.
!A
!B INSTRUCTIONS:
!B
!B 	DISK RADIUS: Enter the radius of the disk to be created.
!B
!B 	PICK SURFACE: Pick the surface that will be tangent to the constructed
!B 		disk.
!B
!B 	PICK POINT ON SURFACE: Pick the point on the surface that will
!B 		determine the tangent point of the disk and the surface.
!B 		The point picked must already be defined on the surface.
!B
!C NOTES:
!C
!C 	The U contours of a disk are the circles and the V contours are the
!C 	radial lines.
!C

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

DIM Destination$[256]
DIM Answer$[256]

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

Start:!
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Xlength)
Radius=InputRadius("DISK RADIUS")
IF ExitScript(Destination$) THEN Leave

Intersect2:!

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

Stat=SetPickMask(WsPickNoSurf)

Pick_point: Stat=SetInputFormat("n4","")
Point=PickSpecificEnt("PICK POINT ON SURFACE ",WsPickPoints)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Point) THEN Pick_point

Stat=SetLastPoint(Point,WsXyzInput)
Stat=SetPickMask(WsPickAll)

Stat=Set3dInterOffset(0.0)
P1=TangentPlane(WsDiskSolidEnt,Surface,Point,Radius,Tol)

ActivateUndo
Stat= AdvanceUndoNumber("disk")
Stat= AddItemToUndo(WsUBCreateMode,P1)
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
