
! script name: contours.d/boundarybox
! topic: make boundarys from entities in a box

!A
!A NAME:
!A
!A 	Make Boundarys in a box.
!A
!A DESCRIPTION:
!A
!A	This script make boundarys from the elements in a box. It creates
!A	a contour by looking for endpoint connections. If there is a 
!A	multi element junction it will create multiple contours.
!A	It will then analyze the closed contours to form boundary entities
!A	with interior and exterior elements.
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view that elements will be
!B 		colored in.
!B
!B 	PICK FIRST CORNER OF PICK ZONE: Pick a corner of the box.
!B
!B 	PICK SECOND CORNER OF PICK ZONE: Pick the other corner of the view box.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: make contours in a box ")

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

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

Group_loop:!
Group=CreateGroup("TEMPGROUP")

Vnum= LastPickView
Stat=PickBox(Group,Vnum,WsPickPen)
IF (ExitScript(Destination$)) THEN Leave

Cont_group= FindClosedContours(Group)
Num_contours= GroupCount(Cont_group)
Stat=DeleteEntity(Group)

IF Num_contours THEN
	Color1= CurrentColor
	FOR I=1 TO Num_contours
		Contour= GroupElement(Cont_group,I)
      		Stat=AutoNumberCont(Contour)
		IF Color1 THEN
      			Stat=SetColor(Contour,Color1)
			Stat=PlotEntity(Contour)
		END IF
	NEXT I
	Boundary_group= CreateBoundarys(Cont_group)
	Fill_pen= CurrentColor
	IF Fill_pen=0 THEN Fill_pen= 18
	IF ValidGeometry(Boundary_group) THEN
		IF Fill_boundary THEN
			Fill_group= FillBoundaryGrp(Boundary_group,Fill_pen)
		END IF
		Stat= SetSelectedFlag(Boundary_group,WsTrue)
		Stat= PlotEntity(Boundary_group)
		IF Fill_boundary THEN
			Stat=DeleteEntity(Fill_group)
		END IF
		Stat=DeleteEntity(Boundary_group)
	END IF
END IF
Stat=DeleteEntity(Cont_group)

GOTO Group_loop

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


