
! script name: vpkconvert.d/vpksectioncontours
! var_solids: gives the section contours of a body

!A
!A NAME:
!A
!A 	Section Contours  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script gives the section contours of a solid body.
!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: z section contours ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Body$[256]
DIM Point$[256]
DIM Z_var$[256]


Stat= GLPlotOn
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave
Ploop:!
ActivateUndo
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(WsGeometryZ)
Stat=SetInputFormat("n4a1=",",P,")
Stat=SetEqualsValue(0.0)
Zvalue=GetValue("Z VALUE  Pick ",Answer$)
Stat=SetPickReturn(Pick_return)
IF ExitScript(Destination$) THEN Leave
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)
        Zvalue= ZPointValue(Pc)
        Picked_point=1
ELSE
        No_z_var= LastVariableInput(Z_var$)
        Picked_point=0
        Pc_created= WsFalse
END IF

Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CONTOUR: z section contours")
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("Z Value",ZPointValue(Pc))
        Stat= DeleteEntity(Pc)
ELSE
        IF No_z_var THEN
                V1= FreeParameter("Z Value",Zvalue)
        ELSE
                V1= FreeParameter("Z Value",Z_var$)
        END IF
END IF
Group= WPKSectionContours(Body$,V1)
Stat= AutoNameGroup(Group,Name$)
RecordFunctionOff
IF ValidGeometry(Group) THEN
	Stat= PlotEntity(Group)
	ActivateUndo
        Stat= AdvanceUndoNumber("z section contours")
        Stat= AddGroupToUndo(WsUBCreateMode,Group,0,WsTrue)
	Keep_record= WsTrue
ELSE
	Keep_record= WsFalse
END IF
RecordFunctionOn
Stat= DeleteEntity(Group)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

IF Keep_record= WsFalse THEN
        DelLastVarRecord
ELSE
        Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Ask_value

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