
! script name: contours.d/makeboundary
! topic: make a boundary from exterior and interior contours

!A
!A NAME:
!A
!A 	Make Boundary
!A
!A DESCRIPTION:
!A
!A	This script make a boundary entity from the exterior contour and
!A 	the interior islands.
!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 	NUMBER OF ISLANDS: Enter the number of interior islands.
!B
!B 	PICK ISLAND # : Pick the interior islands.  The island contour(s)
!B 		had to be created by types or by auto link.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: make boundary ")

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


DeActivateUndo
Fill_boundary=1
Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

Boundary_loop:!
Contour=PickGroupEnt("PICK EXTERIOR CONTOUR")
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidGeometry(Contour)) THEN Boundary_loop

Closed=IsContClosed(Contour)
IF NOT Closed THEN Boundary_loop
Stat= SetSelectedFlag(Contour,WsTrue)
Stat= PlotEntity(Contour)

Stat=SetInputFormat("n0=","")
Stat= SetEqualsValue(0)
Nisles=GetValue("NUMBER OF ISLANDS",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Islands=CreateGroup("ISLANDS")
FOR I=1 TO Nisles
	Isle=PickGroupEnt("PICK ISLAND #"&VAL$(I))
	IF (ExitScript(Destination$)) THEN Leave
	Stat=AddToGroup(Islands,Isle)
	Stat= SetSelectedFlag(Isle,WsTrue)
	Stat= PlotEntity(Isle)
NEXT I
Islands1= CopyEntity(Islands)
Stat= NameEntity(Islands1,"Boundary islands")
Boundary1= MakeBoundary(Contour,Islands1,"Boundary")
Stat=DeleteEntity(Islands)

Fill_pen= CurrentColor
IF Fill_pen=0 THEN Fill_pen= 18
IF Fill_boundary THEN
       Fill1= FillBoundary(Boundary1,Fill_pen)
END IF
Stat= SetSelectedFlag(Boundary1,WsTrue)
Stat= PlotEntity(Boundary1)

GOTO Boundary_loop

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