
! script name: vpksheets.d/vpkplaneaxis
! var_solids: construct plane sheet body using axis line

!A
!A NAME:
!A
!A 	Sheet: Axis Plane	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a plane of specified length, width, 
!A 	with the axis line as its normal vector.
!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 AXIS LINE: Pick the line to be used as the axis of the plane.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: axis line plane ")

DIM Destination$[256]
DIM Answer$[256]
DIM Xlength_var$[256]
DIM Ylength_var$[256]
DIM Tilt_var$[256]
DIM Name$[256]
DIM Axis_line$[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

Stat= GLPlotOn
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_axis:!
Stat=SetInputFormat("n4","")
Axis_line=PickSpecificEnt("PICK AXIS LINE",WsPickLines)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Axis_line) THEN Pick_axis
Stat= EntityNameCheck(Axis_line,Axis_line$)

T=LastPickPara
IF T<=0.5 THEN
        Direction= WsForward
ELSE
        Direction= WsReverse
END IF

On_center=1
WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: Axis line plane")
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
P1=AxisLinePlane(Axis_line$,V1,V2,V3,On_center,Direction)
RecordFunctionOff
IF ValidGeometry(P1) THEN
        Make_record= WsTrue
        RecordFunctionOn
        Pkbody=WPKBasicSolid(P1)
        Stat= WPKNameBody(Pkbody,Name$)
        Stat= WPKSetBodyParent(Pkbody)
        Stat= DeleteEntity(P1,WsTrue)
        RecordFunctionOff
ELSE
        Make_record= WsFalse
END IF
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF Make_record= WsFalse THEN
        DelLastVarRecord
ELSE
        Stat= WPKSolidRecordOn(Curr_record)
        ActivateUndo
        Stat= AdvanceUndoNumber("plane sheet")
        Stat= AddItemToUndo(WsUBPKSessionMark)
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
        WPKErrorCheck
END IF
GOTO Cloop

Leave:!
Stat=DeleteEntity(Pt)

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