
! script name: draft.d/fillinbox
! topic: fill areas created by making boundarys in a box.

!A
!A NAME:
!A
!A 	Area Fill in Box
!A
!A DESCRIPTION:
!A
!A	This script area fills 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
!B 		elements will be 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
!B 		corner of the view box.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: area fill in a box ")

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

DeActivateUndo
Current_pen= CurrentColor
RaiseColorBox
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
	Stat= SetSelectedFlag(Cont_group,WsTrue)
	Stat=PlotEntity(Cont_group)
	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
	Stat= SetSelectedFlag(Cont_group,WsFalse)
	Boundary_group= CreateBoundarys(Cont_group)
	IF ValidGeometry(Boundary_group) THEN
		Fill_pen= CurrentColor
		IF Fill_pen= 0 THEN Fill_pen= 18
		Fill_group= FillBoundaryGrp(Boundary_group,Fill_pen)
		Stat=DeleteEntity(Fill_group)
		Stat=DeleteEntity(Boundary_group)
	END IF
END IF
Stat=DeleteEntity(Cont_group)

GOTO Group_loop

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


