
! script name: vdraft.d/fillboundary
! var_topic: fill the area in a boundary

!A
!A NAME:
!A
!A 	Fill A Boundary	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script Fills the area inside a boundary entity.
!A

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

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


Start:!
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

ActivateUndo
RaiseColorBox
Boundary_loop:!
Stat=SetInputFormat("n4","")
Contour=PickGroupEnt("PICK CONTOUR IN BOUNDARY")
IF (ExitScript(Destination$)) THEN Leave
Hatch_boundary= FindBoundary(Contour)
IF (NOT ValidDependency(Hatch_boundary)) THEN Start
Stat= EntityNameCheck(Hatch_boundary,Boundary$)
Stat= SetSelectedFlag(Hatch_boundary,WsTrue)
Stat= PlotEntity(Hatch_boundary)

Fill_pen= CurrentColor
Stat= GenerateVarName(WsAreaFillEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("DIM: Area Fill Boundary")
Stat= SetRecDelLastExec
V1= FreeParameter("Fill pen",Fill_pen)
Fill1= FillBoundary(Boundary$,V1)
Stat= NameEntity(Fill1,Fill_name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Fill1)
Stat= PlotEntity(Boundary$)
IF NOT ValidGeometry(Fill1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("fill boundary")
	Stat= AddItemToUndo(WsUBCreateMode,Fill1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
Stat= SetSelectedFlag(Hatch_boundary,WsFalse)
Stat= PlotEntity(Hatch_boundary)

GOTO Boundary_loop

Leave:!
IF ValidGeometry(Hatch_boundary) THEN
	Stat= SetSelectedFlag(Hatch_boundary,WsFalse)
	Stat= PlotEntity(Hatch_boundary)
END IF
LowerColorBox
Stat=SetPickMask(WsPickAll)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	  LOAD "typecontrol"
ELSE
	  LOAD Destination$
END IF
END

