
! script name: vsolids.d/normalplane
! var_topic: construct plane normal to a curve element

!A
!A NAME:
!A
!A 	Plane: Normal plane to curve element	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a plane of specified length, width, 
!A 	normal to an entity at a point.
!A
!B INSTRUCTIONS:
!B
!B 	X LENGTH: Enter the length of the plane measured along the X axis.
!B
!B 	Y LENGTH: Enter the length of the plane measured along the Y axis.
!B
!B 	PICK NORMAL ELEMENT: Pick the element that defines the planes normal.
!B
!C NOTES:
!C
!C 	The U contours of a plane are the lines parallel to the length of
!C 	the plane ( parallel to X axis in an unoriented plane ) and the V
!C 	contours are the lines parallel to the width of the plane ( parallel
!C 	to Y axis in an unoriented plane ).
!C

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

DIM Destination$[256]
DIM Answer$[256]
DIM Xlength_var$[256]
DIM Ylength_var$[256]
DIM Tilt_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= 100
	Ylength= 100
ELSE
	Xlength= 5
	Ylength= 5
END IF


Cloop:!
Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Xlength)
XLength=GetValue("X LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_xlength_var= LastVariableInput(xlength_var$)

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Ylength)
YLength=GetValue("Y LENGTH",Answer$)
IF ExitScript(Destination$) THEN Leave
No_ylength_var= LastVariableInput(ylength_var$)

Stat=SetAngleEquals(Tilt_angle)
Tilt_angle=InputAngle("TILT ANGLE ",WsSigned)
IF ExitScript(Destination$) THEN Leave
No_tilt_var= LastVariableInput(tilt_var$)


Pick_loop:Stat=SetInputFormat("n4","")
Stat=SetPickMask(WsPickNoSurf)
E1=PickEntity("PICK NORMAL ENTITY")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Pick_loop
Stat= EntityNameCheck(E1,Element$)
Stat=SetPickMask(WsPickAll)


Pick_point:Stat=SetInputFormat("n4=","")
E1=PickEntity("PICK POINT ON ENTITY")
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)


On_center=1
Stat= GenerateVarName(WsPlaneSolidEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("PLANE: Normal to entity")
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("Xlength",Xlength)
ELSE
        V1= FreeParameter("Xlength",Xlength_var$)
END IF
IF No_ylength_var THEN
        V2= FreeParameter("Ylength",Ylength)
ELSE
        V2= FreeParameter("Ylength",Ylength_var$)
END IF
IF No_tilt_var THEN
        V3= FreeParameter("Tilt Angle",Tilt_angle)
ELSE
        V3= FreeParameter("Tilt Angle",Tilt_var$)
END IF
Axis_line=TangentLine(Element$,Pc,WsTRIMMED)
P1=AxisLinePlane(Axis_line,V1,V2,V3,On_center,Direction)
Stat= NameEntity(P1,Name$)
Stat= DeleteEntityList(Axis_line,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 Pick_loop

Leave:!
Stat=SetPickMask(WsPickAll)
Stat=SetInputFormat("n4","")
Stat=DeleteEntity(Pt)
Stat= DeleteEntity(Axis_line)

IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
