
! script name: vpksheets.d/vpkplanecenter
! var_solids: construct plane of specified length, width, and orientation

!A
!A NAME:
!A
!A 	Sheet: Plane center	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a plane sheet body of specified length, 
!A	width, and orientation.
!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 	REFERENCE POINT ABS X,Y,Z: Enter the X,Y,Z coordinates of the lower
!B 		left-hand corner of the plane.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	ROTATION ANGLE: Enter the orientation angle of the axis of the plane
!B 		in the XY plane.
!B
!B 	X AXIS TILT ANGLE: This represents the angle of tilt of the axis of
!B 		the plane around the X axis.
!B
!B 	Y AXIS TILT ANGLE: This represent the angle of tilt of the axis of
!B 		the plane around the Y axis.
!B
!# see also - points.d/xyzinput.hlp

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

DIM Destination$[256]
DIM Answer$[256]
DIM Xlength_var$[256]
DIM Ylength_var$[256]
DIM Name$[256]
DIM Center$[256]
DIM Xangle_var$[256]
DIM Yangle_var$[256]
DIM Zangle_var$[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$)

Pick_point:Stat=SetInputFormat("n4=","")
Pc=XyzInput("CENTER POINT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Pick_point
E1= LastPickEnt
Pick_para= LastPickPara
Pick_return= CurrPickReturn
IF NOT ValidDependency(E1) THEN
        E1= CopyEntity(Pc)
        Stat= EntityNameCheck(E1,Center$)
        Pc_created= WsTrue
ELSE
        Stat= EntityNameCheck(E1,Center$)
        Pc_created= WsFalse
END IF
Stat=SetLastPoint(Pc)
Stat= DeleteEntity(Pc)

Stat=SetAngleEquals(0)
Zangle=InputAngle("ROTATION ANGLE ",WsSigned)
IF ExitScript(Destination$) THEN Leave
No_zangle_var= LastVariableInput(Zangle_var$)

Stat=SetAngleEquals(0)
Xangle=InputAngle("X AXIS TILT ANGLE ",WsSigned)
IF ExitScript(Destination$) THEN Leave
No_xangle_var= LastVariableInput(Xangle_var$)

Stat=SetAngleEquals(0)
Yangle=InputAngle("Y AXIS TILT ANGLE ",WsSigned)
IF ExitScript(Destination$) THEN Leave
No_yangle_var= LastVariableInput(Yangle_var$)

On_center=1
WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: plane center")
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Center$,Pick_para,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Center$,Pick_para,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_xangle_var THEN
        V3= FreeParameter("X Angle",Xangle)
ELSE
        V3= FreeParameter("X Angle",Xangle_var$)
END IF
IF No_yangle_var THEN
        V4= FreeParameter("Y Angle",Yangle)
ELSE
        V4= FreeParameter("Y Angle",Yangle_var$)
END IF
IF No_zangle_var THEN
        V5= FreeParameter("Z Angle",Zangle)
ELSE
        V5= FreeParameter("Z Angle",Zangle_var$)
END IF
Trans1=AngleTransform(Pc,V3,V4,V5,WsWorkplaneVals)
C1=Plane3d(Trans1,V1,V2,On_center)
RecordFunctionOff
IF ValidGeometry(C1) THEN
        Make_record= WsTrue
        RecordFunctionOn
        Pkbody=WPKBasicSolid(C1)
        Stat= WPKNameBody(Pkbody,Name$)
        Stat= WPKSetBodyParent(Pkbody)
        Stat= DeleteEntity(C1,WsTrue)
        RecordFunctionOff
ELSE
        Make_record= WsFalse
END IF
RecordFunctionOn
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF Make_record= WsFalse THEN
	IF Pc_created THEN Stat= DeleteEntity(Center$)
        DelLastVarRecord
ELSE
	Stat= WPKSolidRecordOn(Curr_record)
	ActivateUndo
	Stat= AdvanceUndoNumber("plane sheet")
	IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Center$)
	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
