
! script name: pksoliddraft.d/hatchsection
! solids: crosshatch a section of a solid

!A
!A NAME:
!A
!A 	Hatch Section
!A
!A DESCRIPTION:
!A
!A 	This script will cross hatch a section through a solid model. 
!A	The current workplane must be parallel to the plane of the section.
!A	The hatch lines will be in its spacial location on the solid model.
!A	
!A
!A~ image location - images/pkhatchsection.gif
!A
!B INSTRUCTIONS:
!B
!B	PICK BODY: Pick the body to be sectioned.
!B
!B	Z LEVEL: Enter the z level of the slice in
!B 		 the current workplane.
!B
!# see also - htdocs/help.d/parasolids.htm


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

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

Units= CurrentUnits
IF Units= WsMetric THEN
        Hwidth= 6.25
ELSE
        Hwidth= 0.25
END IF
Hatch_pattern= 1
HAngle= 60
Hatch_pen= 19
Ext_ltype= 0

Hatch_pattern=NamedVarVal("Section hatch pattern",WsPKSectionVars,Hatch_pattern)
Hwidth=NamedVarVal("Section hatch width",WsPKSectionVars,Hwidth)
HAngle=NamedVarVal("Section hatch angle",WsPKSectionVars,Angle)
Hatch_pen=NamedVarVal("Section hatch color",WsPKSectionVars,Hatch_pen)
Ext_ltype=NamedVarVal("Exterior line type",WsPKSectionVars,Ext_ltype)

V5=CreateVariable("Section hatch pattern",WsPKSectionVars,Hatch_pattern)
V6=CreateVariable("Section hatch width",WsPKSectionVars,Hwidth)
V7=CreateVariable("Section hatch angle",WsPKSectionVars,HAngle)
V8=CreateVariable("Section hatch color",WsPKSectionVars,Hatch_pen)
V9=CreateVariable("Exterior line type",WsPKSectionVars,Ext_ltype)


Stat= GLPlotOn
Ploop:!
ActivateUndo

E1=WPKPickEntity("PICK SOLID BODY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Ploop

Body= WPKParentBody(E1)
Body_type= WPKBodyType(Body)
IF Body_type<> WsPKSolidBody THEN Ploop


Zlevel:!
Ask_value:!
Pick_return= CurrPickReturn
Stat=SetPickReturn(WsGeometryZ)
Stat=SetInputFormat("n4a1=",",P,")
Stat=SetEqualsValue(0.0)
Zlevel=GetValue("Z LEVEL  Pick ",Answer$)
Stat=SetPickReturn(Pick_return)
IF ExitScript(Destination$) THEN Leave
IF Answer$= "P" THEN
        Stat=SetInputFormat("n4","")
        Pc=XyzInput("PICK",WsXyzInput)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pc) THEN Ask_value
        Zlevel= ZPointValue(Pc)
        Stat= DeleteEntity(Pc)
END IF


Group= WPKHatchSection(E1,Hatch_pattern,Zlevel,Hwidth,Hangle,Hatch_pen,WsTrue,Ext_ltype)

ActivateUndo
Stat= AdvanceUndoNumber("hatch section")
Stat= AddGroupToUndo(WsUBCreateMode,Group,0,WsTrue)
Stat= DeleteEntity(group)

GOTO Zlevel

Leave:!
Stat=SetPickReturn(WsGeometryEnd)
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
