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

!A
!A NAME:
!A
!A 	Y Section
!A
!A DESCRIPTION:
!A
!A 	This script makes a sheet body which is a y section of
!A 	the picked body. The original body is unmodified.
!A
!B~ image location - images/pkysection.gif
!B
!B INSTRUCTIONS:
!B
!B 	PICK BODY: Pick the body to be sectioned.
!B
!B 	Y VALUE: Enter the y 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: y 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(WsGeometryY)
Stat=SetInputFormat("n4a1=",",P,N,")
Stat=SetEqualsValue(0.0)
Pkbody1= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody1) THEN
	Yvalue=GetValue("Y VALUE  Pick, New body ",Answer$)
ELSE
	Yvalue=GetValue("Y 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
        Yvalue= YPointValue(Pc)
        Stat= DeleteEntity(Pc)
END IF


WPKClearErrorFlag
G1= WPKZPlaneSection(Pkbody,Yvalue,WsYZPlane)
Stat= DeleteEntity(G1)

ActivateUndo
Stat= AdvanceUndoNumber("y 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


