
! script name: draft.d/hatchinbox
! topic: crosshatch from entities in a box

!A
!A NAME:
!A
!A 	Crosshatch In Box
!A
!A DESCRIPTION:
!A
!A	This script will 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
!A~ image location - images/crosshatch.gif
!A
!B INSTRUCTIONS:
!B
!B 	SELECT VIEW FOR SELECTION BOX: Pick the view
!B 		that elements will be colored in.
!B
!B 	PICK FIRST CORNER OF PICK ZONE: Pick a corner
!B 		of the box.
!B
!B 	PICK SECOND CORNER OF PICK ZONE: Pick the other
!B 		corner of the view box.
!B
!B OPTIONS:
!B
!B      Hatch pattern data is contained in Named variables.
!B
!# see also - draft.d/hatchdata

stat=ChangeLabelStr("ScriptNameStatus","Function: cross hatch in a box ")

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

ActivateUndo
IF Units= WsMetric THEN
        Hwidth= 6.25
ELSE
        Hwidth= 0.25
END IF
HatchVarsType= 20021
Hatch_pattern= 1.0
Hwidth= 0.25
Angle= 60
Hatch_pen= 19.0

Hatch_pattern=NamedVarVal("Hatch pattern",HatchVarsType,Hatch_pattern)
Hwidth=NamedVarVal("Hatch width",HatchVarsType,Hwidth)
Angle=NamedVarVal("Hatch angle",HatchVarsType,Angle)
Hatch_pen=NamedVarVal("Hatch color",HatchVarsType,Hatch_pen)
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
	Boundary_group= CreateBoundarys(Cont_group)
	IF ValidGeometry(Boundary_group) THEN
		stat= SetCurrentColor(Hatch_pen)
		Cross_group=CrossHatchBdyGrp(Boundary_group,Hatch_pattern,Hwidth,Angle,Hatch_pen)

		ActivateUndo
		Stat= AdvanceUndoNumber("crosshatch")
		Stat= AddGroupToUndo(WsUBCreateMode,Cross_group,0,WsTrue)

		Stat=DeleteEntity(Cross_group)
		Stat=DeleteGroup(Boundary_group,WsTrue)
	END IF
END IF
Stat=DeleteSubGroups(Cont_group)
Stat=DeleteEntity(Group)

GOTO Group_loop

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


