
! script name: pksolids.d/pktangentplane
! solids: tangent plane to a surface

!A
!A NAME:
!A
!A 	Plane: Tangent Plane
!A
!A DESCRIPTION:
!A
!A 	This script will create a plane tangent to a surface, at a point on
!A 	the surface.
!A
!B INSTRUCTIONS:
!B
!B 	PLANE LENGTH: Enter the length of the plane.
!B
!B 	PICK SURFACE: Pick the surface that will be tangent
!B 		to the constructed plane.
!B
!B 	PICK POINT ON SURFACE: Pick the point on the surface
!B 		that will determine the tangent point of the plane and
!B 		the surface.  The point picked must already be defined
!B 		on the surface.
!B

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

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

ActivateUndo
Xlength=1.0
Ylength=1.0
Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)
Stat= GLPlotOn

Start:!

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Xlength)
XLength=GetValue("PLANE LENGTH")
IF ExitScript(Destination$) THEN Leave
Ylength=Xlength

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(WsPlaneSolidEnt,Surface,Point,Xlength,Tol)
WPKClearErrorFlag
S1=WPKMakeBsurf(P1)
Stat=DeleteEntity(P1)

ActivateUndo
Stat= AdvanceUndoNumber("plane sheet body")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
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
