
! script name: draft.d/crosshatch
! topic: hatch the area inside exterior contour and outside interior islands

!A
!A NAME:
!A
!A 	Crosshatch
!A
!A DESCRIPTION:
!A
!A	This script Hatches the area inside the exterior contour and outside
!A 	the interior islands.
!A
!A~ image location - images/crosshatch.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK EXTERIOR CONTOUR: 	Pick the Exterior boundary of the hatch area.
!B 		The contour had to be created by types or by auto link.
!B
!B 	NUMBER OF ISLANDS: Give number of interior islands.
!B
!B 	PICK ISLAND # : Pick the interior islands. The contour had to be
!B 		created by types or by auto link.
!B
!B OPTIONS:
!B
!B 	Hatch pattern data is contained in Named variables.
!B
!# see also - draft.d/hatchdata

stat=ChangeLabelStr("ScriptNameStatus","Function: crosshatch ")

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

Current_pen= CurrentColor

ActivateUndo
Active_workplane=0
Work=CurrentWorkplane
IF (ValidGeometry(Work)) THEN Active_workplane=1

Units= CurrentUnits

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)


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


Closed=IsContClosed(Contour)
IF NOT Closed THEN Boundary_loop

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

Islands=CreateGroup("ISLANDS")
FOR I=1 TO Nisles

	Isle=PickEntity("PICK ISLAND #"&VAL$(I))
	IF (ExitScript(Destination$)) THEN Leave

	Stat=AddToGroup(Islands,Isle)

NEXT I

stat= SetCurrentColor(Hatch_pen)

Cross_group=CrossHatch(Hatch_pattern,Contour,Islands,Hwidth,Angle,Hatch_pen)

ActivateUndo
Stat= AdvanceUndoNumber("cross hatch")
Stat= AddGroupToUndo(WsUBCreateMode,Cross_group,WsTrue,WsFalse)

GOTO Boundary_loop

Leave:!
Stat=DeleteEntity(Islands)
V1=CreateVariable("Hatch pattern",HatchVarsType,Hatch_pattern)
V2=CreateVariable("Hatch width",HatchVarsType,Hwidth)
V3=CreateVariable("Hatch angle",HatchVarsType,Angle)
V4=CreateVariable("Hatch color",HatchVarsType,Hatch_pen)


IF Active_workplane THEN
	Stat=SetWorkplane(Work)
ELSE
	StdWorkplane
END IF
stat= SetCurrentColor(Current_pen)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	  LOAD "typecontrol"
ELSE
	  LOAD Destination$
END IF
END

