
! script name: vpksolids.d/vpkplaneboundary
! var_solids: construct a sheet body from a contour with interiors

!A
!A NAME:
!A
!A 	Bounded Sheet VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script makes a sheet body which corresponds to the interior of
!A	a closed contour with interior holes.
!A
!A~ image location - images/pkboundedsheet.gif
!A
!B INSTRUCTIONS:
!B
!B	PICK EXTERIOR CONTOUR: Pick the exterior contour to be used. 
!B 		This contour is unchanged by this operation.
!B
!B	# OF INTERIOR CONTOURS: Enter the number of interior contours.
!B
!B	PICK INTERIOR CONTOUR #: Pick the interior contours.
!B
!C NOTES:
!C	
!C	The contour must not be self crossing. An open contour will
!C	automatically be closed by joining the end points.
!C
!# see also - htdocs/help.d/parasolids.htm

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

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Contour$[256]
DIM Island$[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)


WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SHEET: Bounded plane")
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
Pkbody=WPKContPlaneBody(Contour$,Isles)
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 plane")
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
