
! script name: solids.d/boundedplane
! 3dtopic: make a plane bounded by  exterior and interior closed contours

!A
!A NAME:
!A
!A 	Bounded Plane
!A
!A DESCRIPTION:
!A
!A	This script make a plane entity trimmed to an exterior and
!A 	the interior closed contours.
!A
!B INSTRUCTIONS:
!B
!B 	PICK EXTERIOR CONTOUR: Pick the exterior boundary of the boundary.
!B 		The contour had to be created by types or by auto link.
!B
!B 	# OF INTERIOR CONTOURS: Enter the number of interior islands.
!B
!B 	PICK INTERIOR CONTOUR # : Pick the interior contours.
!B		The island contour(s) had to be created by 
!B		types or by auto link.
!B
!C NOTE:
!C
!C	The exterior and interior contours must be closed.
!C	The construction must take place in the workplane of the contours.
!C	The contours must be flat relative to the plane created.
!C

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

DIM Destination$[256]
DIM Answer$[256]


Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Tol=NamedVarVal("3D Trimming Tol",Ws3DSystemVars,0.005)

Contour_loop:!
ActivateUndo
Stat=SetPickMask(WsPickNoSurf)
Contour=PickGroupEnt("PICK EXTERIOR CONTOUR")
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidGeometry(Contour)) THEN Contour_loop
Stat=SetPickMask(WsPickGeometry)

Closed=IsContClosed(Contour)
IF NOT Closed THEN Contour_loop
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
	Closed=IsContClosed(Isle)
	IF NOT Closed 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)

Plane1= BoundedPlane(Contour,Islands,Tol)

Stat= PlotEntity(Contour)
Stat= PlotEntity(Islands)
Stat=DeleteEntity(Islands)

ActivateUndo
Stat= AdvanceUndoNumber("bounded plane")
Stat= AddItemToUndo(WsUBCreateMode,Plane1)
GOTO Contour_loop

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