
! script name: vpksoliddraft.d/vpkplanarhatch
! var_solids: assign a planar hatch attribute

!A
!A NAME:
!A
!A 	Planar Hatch   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script will assign a planar hatching attribute to a
!A	parasolids face. This attribute is a property of the solid model
!A	and can be read by other systems which use the parasolid kernel.
!A
!A	The hatch lines on the face are the intersections of a series
!A	of equally spaced parallel planes whose normals are in the
!A	specified direction. 
!A
!A~ image location - images/pkplanarhatch.gif
!A
!A NOTE:
!A
!A	This attribute may be computationally intensive for some surfaces.
!A	The computational overhead for planar surfaces is minimal.
!A
!# see also - htdocs/help.d/parasolids.htm

stat=ChangeLabelStr("ScriptNameStatus","Function: assign planar hatch ")

DIM Destination$[256]
DIM Answer$[256]
DIM Face$[256]
DIM Spacing_var$[256]
DIM Xdir_var$[256]
DIM Ydir_var$[256]
DIM Zdir_var$[256]

ActivateUndo
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Units= CurrentUnits
IF Units= WsMetric THEN
        Pitch= 5
ELSE
        Pitch= 0.25
END IF

Start: !

Stat= SetEqualsValue(Pitch)
Stat=SetInputFormat("n4=","")
Pitch=GetValue("SPACING OF HATCH PLANES")
IF ExitScript(Destination$) THEN Leave
No_space_var= LastVariableInput(Spacing_var$)

Stat= SetEqualsValue(1)
Stat=SetInputFormat("n4=","")
Dx=GetValue("X DIRECTION OF HATCH PLANES")
IF ExitScript(Destination$) THEN Leave
No_xdir_var= LastVariableInput(Xdir_var$)

Stat= SetEqualsValue(1)
Stat=SetInputFormat("n4=","")
Dy=GetValue("Y DIRECTION OF HATCH PLANES")
IF ExitScript(Destination$) THEN Leave
No_ydir_var= LastVariableInput(Ydir_var$)

Stat= SetEqualsValue(1)
Stat=SetInputFormat("n4=","")
Dz=GetValue("Z DIRECTION OF HATCH PLANES")
IF ExitScript(Destination$) THEN Leave
No_zdir_var= LastVariableInput(Zdir_var$)


Face_loop:!
Stat=SetInputFormat("a1",",N,")
E1=WPKPickEntity("PICK FACE   New spacing ",WsPKPickFace,Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF Answer$="N" THEN Start
IF NOT WPKIsEntity(E1) THEN Face_loop
Stat= EntityNameCheck(E1,Face$)


WPKClearErrorFlag
RecordFunctionOn
Stat= RecordDescr("FACE: planar hatch")
IF No_space_var THEN
        V1= FreeParameter("Spacing",Pitch)
ELSE
        V1= FreeParameter("Spacing",Spacing_var$)
END IF
IF No_xdir_var THEN
        V2= FreeParameter("X direction",Dx)
ELSE
        V2= FreeParameter("X direction",Xdir_var$)
END IF
IF No_ydir_var THEN
        V3= FreeParameter("Y direction",Dy)
ELSE
        V3= FreeParameter("Y direction",Ydir_var$)
END IF
IF No_zdir_var THEN
        V4= FreeParameter("Z direction",Dz)
ELSE
        V4= FreeParameter("Z direction",Zdir_var$)
END IF
Pt= PointXYZ(0,0,0)
Stat= WPKSetPlanarHatch(Face$,Pt,V1,V2,V3,V4)
Stat= WPKUpdateBody(Face$)
Stat= DeleteEntity(Pt)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("planar face hatch")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
GOTO Face_loop

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