
! script name: vpksolids.d/vpkblock
! var_solids: construct a block in the current workplane

!A
!A NAME:
!A
!A 	Solid Block VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a solid rectangular block.  The position
!A 	of the block is specified by the center of the bottom face.
!A
!B INSTRUCTIONS:
!B
!B	X LENGTH:  Total length of the block in the X direction.
!B
!B	Y LENGTH:  Total length of the block in the Y direction.
!B
!B	Z LENGTH:  Total length of the block in the Z direction.
!B
!B	LOCATION POINT: Location of the center of the bottom face.
!B
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: block")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Xlength$[256]
DIM Ylength$[256]
DIM Zlength$[256]
DIM Center$[256]

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

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

Stat= GLPlotOn
Cloop:!

Stat=SetInputFormat("n4=","")
Stat=SetDepthEquals(Xlength)
XLength=InputDepth("X LENGTH")
IF ExitScript(Destination$) THEN Leave
No_xlength_var= LastVariableInput(Xlength$)

Stat=SetInputFormat("n4=","")
Stat=SetDepthEquals(Ylength)
YLength=InputDepth("Y LENGTH")
IF ExitScript(Destination$) THEN Leave
No_ylength_var= LastVariableInput(Ylength$)

Stat=SetInputFormat("n4=","")
Stat=SetDepthEquals(Zlength)
ZLength=InputDepth("Z LENGTH")
IF ExitScript(Destination$) THEN Leave
No_zlength_var= LastVariableInput(Zlength$)

Pick_point:Stat=SetInputFormat("n4=","")
Pc=XyzInput("LOCATION 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)


WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("BLOCK: Define")
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("X Length",XLength)
ELSE
        V1= FreeParameter("X Length",Xlength$)
END IF
IF No_ylength_var THEN
        V2= FreeParameter("Y Length",YLength)
ELSE
        V2= FreeParameter("Y Length",Ylength$)
END IF
IF No_zlength_var THEN
        V3= FreeParameter("Z Length",ZLength)
ELSE
        V3= FreeParameter("Z Length",Zlength$)
END IF
E1=WPKBlock(Pc,V1,V2,V3)
Stat= WPKNameBody(E1,Name$)
Stat= WPKSetBodyParent(E1)
Stat= DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("solid block")
IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Center$)
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
	
GOTO Pick_point

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