
! script name: vpksection.d/vpkysectionsheet
! var_solids: makes a sheet body which is a plane section.

!A
!A NAME:
!A
!A 	Y Section  VARIATIONAL
!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
!A~ image location - images/pkysection.gif
!A
!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]
DIM Body$[256]
DIM Name$[256]
DIM Point$[256]
DIM Y_var$[256]


Stat= GLPlotOn
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave

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)
END IF
Body_type= WPKBodyType(Pkbody)
IF Body_type<> WsPKSolidBody THEN Ploop
Stat= EntityNameCheck(Pkbody,Body$)

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
Pick_point:Stat=SetInputFormat("n4=","")
        Pc=XyzInput("PICK",WsXyzInput)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pc) THEN Pick_point
        E1= LastPickEnt
        Pick_para= LastPickPara
        Pick_return= CurrPickReturn
        IF NOT ValidDependency(E1) THEN
                 E1= CopyEntity(Pc)
                 Stat= EntityNameCheck(E1,Point$)
                 Pc_created= WsTrue
        ELSE
                 Stat= EntityNameCheck(E1,Point$)
                 Pc_created= WsFalse
        END IF
        Stat=SetLastPoint(Pc)
        Stat= DeleteEntity(Pc)
        Yvalue= YPointValue(Pc)
        Picked_point=1
ELSE
        No_y_var= LastVariableInput(Y_var$)
        Picked_point=0
        Pc_created= WsFalse
END IF

WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SECTION: y section")
IF Picked_point THEN
        SELECT Pick_return
        CASE WsGeometryEnd
                 Pc= ParameterReturnPt(Point$,Pick_para,WsGeometryEnd)
        CASE WsGeometryMid
                 Pc= ParameterReturnPt(Point$,Pick_para,WsGeometryMid)
        CASE WsGeomCenter
                 Pc= ParameterReturnPt(Point$,Pick_para,WsGeomCenter)
        END SELECT
        V1= FreeParameter("Y Value",YPointValue(Pc))
	Stat= DeleteEntity(Pc)
ELSE
        IF No_y_var THEN
                V1= FreeParameter("Y Value",Yvalue)
        ELSE
                V1= FreeParameter("Y Value",Y_var$)
        END IF
END IF
G1= WPKZPlaneSection(Body$,V1,WsYZPlane)
Stat= WPKNameBodyGroup(G1,Name$)
Stat= WPKSetBodyParent(G1,1)
Stat= DeleteEntity(G1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("y section")
IF Pc_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point$)
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

GOTO Ask_value

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


