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

!A
!A NAME:
!A
!A 	Crosshatch	VARIATIONAL
!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
!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: Enter the 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]
DIM Name$[256]
DIM Cname$[256]
DIM Iname$[256]
DEG



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

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=PickGroupEnt("PICK EXTERIOR CONTOUR")
IF (ExitScript(Destination$)) THEN Leave
IF (NOT ValidDependency(Contour)) THEN Boundary_loop
Stat= EntityNameCheck(Contour,Cname$)

Closed=IsContClosed(Contour)
IF NOT Closed THEN Boundary_loop

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

Islands=CreateGroup("ISLANDS")
FOR I=1 TO Nisles
Pick_isle:Isle=PickGroupEnt("PICK ISLAND #"&VAL$(I))
	IF (ExitScript(Destination$)) THEN Leave
	IF (NOT ValidDependency(Isle)) THEN Pick_isle
	Stat= EntityNameCheck(Isle,Iname$)
	Stat=AddToGroup(Islands,Isle)
NEXT I

stat= SetCurrentColor(Hatch_pen)
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("DIM: Crosshatch")
Stat= SetRecDelLastExec
Isles=CreateGroup("")
RecordFunctionOff
FOR I= 1 TO Nisles
	Isle= GroupElement(Islands,I)
	Stat= EntityNameCheck(Isle,Iname$)
	RecordFunctionOn
	Stat= AddToGroup(Isles,Iname$)
	RecordFunctionOff
NEXT I
RecordFunctionOn
V1= FreeParameter("Pattern",Hatch_pattern)
V2= FreeParameter("Width",Hwidth)
V3= FreeParameter("Angle",Angle)
Cross_group=ContourHatch(V1,Cname$,Isles,V2,V3,Hatch_pen)
Stat= NameEntity(Cross_group,Name$)
Stat=DeleteEntity(Isles)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Cross_group)
Stat= PlotEntity(Cname$)
Stat= PlotEntity(Islands)
IF NOT ValidGeometry(Cross_group) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("cross hatch")
	Stat= AddGroupToUndo(WsUBCreateMode,Cross_group,1,WsTrue)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
Stat=DeleteEntity(Islands)

GOTO Boundary_loop

Leave:!
Stat=DeleteEntity(Islands)
Stat=DeleteEntity(Isles)
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

