
! script name: vpksolids.d/vpkboundedblock
! var_solids: construct block from a exterior contour and interior contour holes

!A
!A NAME:
!A
!A	Bounded Block   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script makes a solid block from an exterior synergy contour.
!A	The interior contours become holes in the solid.
!A
!A~ image location - images/pkboundedblock.gif
!A
!B INSTRUCTIONS:
!B
!B	PICK EXTERIOR CONTOUR: Pick the contour to be used.
!B
!B	# OF INTERIOR CONTOURS: Enter the number of interior contours.
!B
!B	PICK INTERIOR CONTOUR #: Pick the interior contours.
!B
!B	HEIGHT ABOVE CONTOUR: Enter the height of the block above the contour.
!B 		Do not enter a negative number.
!B
!B	DEPTH BELOW CONTOUR: Enter the depth of the block below the contour.
!B 		A positive answer will go down.
!B
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: Bounded Block")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Contour$[256]
DIM Island$[256]
DIM Height_var$[256]
DIM Depth_var$[256]

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

Stat= GLPlotOn
Contour_loop:!
ActivateUndo
Stat=SetPickMask(WsPickNoSurf)
Contour=PickGroupEnt("PICK EXTERIOR CONTOUR")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Contour) THEN Contour_loop
Stat= EntityNameCheck(Contour,Contour$)

Stat=SetPickMask(WsPickGeometry)

Stat= SetSelectedFlag(Contour,WsTrue)
Stat= PlotEntity(Contour)

Stat=SetInputFormat("n0=","")
Stat= SetEqualsValue(0)
Nisles=GetValue("# OF INTERIOR CONTOURS  1 2 3 4 5 ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Islands=CreateGroup("ISLANDS")
FOR I=1 TO Nisles
Pick_isle:Stat=SetPickMask(WsPickNoSurf)
        Isle=PickGroupEnt("PICK INTERIOR CONTOUR #"&VAL$(I))
        IF (ExitScript(Destination$)) THEN Leave
	IF NOT ValidDependency(Isle) THEN Pick_isle
        Stat=AddToGroup(Islands,Isle)
        Stat= SetSelectedFlag(Isle,WsTrue)
        Stat= PlotEntity(Isle)
        Stat=SetPickMask(WsPickGeometry)
NEXT I

Stat= SetSelectedFlag(Contour,WsFalse)
Stat= SetSelectedFlag(Islands,WsFalse)


Stat=SetInputFormat("n4=","")
Stat=SetDepthEquals(Height1)
Height1=InputDepth("HEIGHT ABOVE CONTOUR")
IF ExitScript(Destination$) THEN Leave
No_height_var= LastVariableInput(Height_var$)


Stat=SetInputFormat("n4=","")
Stat=SetDepthEquals(Depth1)
Depth1=InputDepth("DEPTH BELOW CONTOUR")
IF ExitScript(Destination$) THEN Leave
No_depth_var= LastVariableInput(Depth_var$)


WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SOLID: Bounded block")
Isles= CreateGroup("interiors")
FOR I=1 TO Nisles
        RecordFunctionOff
        E1= GroupElement(Islands,I)
        Stat= EntityNameCheck(E1,Island$)
        IF ValidDependency(E1) THEN
                RecordFunctionOn
                Stat= AddToGroup(Isles,Island$)
                RecordFunctionOff
        END IF
NEXT I
RecordFunctionOn
IF No_height_var THEN
        V1= FreeParameter("Height",Height1)
ELSE
        V1= FreeParameter("Height",Height_var$)
END IF
IF No_depth_var THEN
        V2= FreeParameter("Depth",Depth1)
ELSE
        V2= FreeParameter("Depth",Depth_var$)
END IF
Pkbody=WPKContourBlock(Contour$,Isles,V1,V2)
Stat= WPKNameBody(Pkbody,Name$)
Stat= WPKSetBodyParent(Pkbody)
Stat= DeleteEntity(Isles)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= DeleteEntity(Islands)
Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("bounded block")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
GOTO Contour_loop


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