
! script name: parasolids.d/pkzsectionsheet
! solids: makes a sheet body which is a plane section.

!A
!A NAME:
!A
!A 	Z Section
!A
!A DESCRIPTION:
!A
!A 	This script makes a sheet body which is a z section of
!A 	the picked body. The original body is unmodified.
!A
!A~ image location - images/pkzsection.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK BODY: Pick the body to be sectioned.
!B
!B 	Z VALUE: Enter the z value of the section
!B 		in the current workplane.
!B
!B NOTES:
!B
!B 	This script is relative to the current workplane.
!B
!B 	The sheet body created for the section is a new body which will
!B 	have the current layer and color. It is recommended that the user
!B 	change layer and/or color to create the section, otherwise
!B 	the section will be hidden by the solid body.
!B
!# see also - htdocs/help.d/parasolids.htm


stat=ChangeLabelStr("ScriptNameStatus","Function: z section sheet body ")

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


Stat= GLPlotOn
Ploop:!
ActivateUndo
Ask_body:!
Pkbody= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody) THEN
        Stat=SetInputFormat("n4","")
        E1=WPKPickEntity("PICK BODY FOR SECTION")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Ploop
        Pkbody= WPKParentBody(E1)
        Body_type= WPKBodyType(Pkbody)
        IF Body_type<> WsPKSolidBody THEN Ploop
ELSE
        Body_type= WPKBodyType(Pkbody)
        IF Body_type<> WsPKSolidBody THEN Leave
END IF

Ask_value:!
Pick_return= CurrPickReturn
Stat=SetPickReturn(WsGeometryZ)
Stat=SetInputFormat("n4a1=",",P,N,")
Stat=SetEqualsValue(0.0)
Pkbody1= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody1) THEN
Zvalue=GetValue("Z VALUE  Pick, New body ",Answer$)
ELSE
Zvalue=GetValue("Z VALUE  Pick ",Answer$)
END IF
Stat=SetPickReturn(Pick_return)
IF ExitScript(Destination$) THEN Leave
IF Answer$="N" THEN Ask_body
IF Answer$= "P" THEN
        Stat=SetInputFormat("n4","")
        Pc=XyzInput("PICK",WsXyzInput)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pc) THEN Ask_value
        Zvalue= ZPointValue(Pc)
        Stat= DeleteEntity(Pc)
END IF


WPKClearErrorFlag
G1= WPKZPlaneSection(Pkbody,Zvalue)
Stat= DeleteEntity(G1)

ActivateUndo
Stat= AdvanceUndoNumber("z section sheet")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

GOTO Ask_value

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


