
! script name: vsolids.d/tangentplane
! var_topic: tangent plane to a surface

!A
!A NAME:
!A
!A 	Plane: Tangent	VARIATIONAL
!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 to the constructed
!B 		plane.
!B
!B 	PICK POINT ON SURFACE: Pick the point on the surface that will
!B 		determine the tangent point of the plane and the surface.
!B

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

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

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

ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
	Xlength= 25
	Ylength= 25
ELSE
	Xlength= 1
	Ylength= 1
END IF


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

Start:!

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

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 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(WsPlaneSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("PLANE: 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_xlength_var THEN
        V1= FreeParameter("Length",Xlength)
ELSE
        V1= FreeParameter("Length",Xlength_var$)
END IF
V2= FreeParameter("Tolerance",Tol)
Stat=Set3dInterOffset(0.0)
P1=TangentPlane(WsPlaneSolidEnt,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("plane")
	Stat= AddItemToUndo(WsUBCreateMode,P1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Intersect2

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