
! script name: parasolids.d/zbodyoutline
! solids: generate the outline contour for a body.

!A
!A NAME:
!A
!A 	Z Body Outline
!A
!A DESCRIPTION:
!A
!A 	This script generates the outline of a body above a z value.
!A
!A
!B INSTRUCTIONS:
!B
!B 	PICK BODY: Pick the body.
!B
!B 	Z LEVEL OF SECTION: Give the z value of the section.
!B
!B 	Z LEVEL OF OUTLINE CURVE: Give the Z coordinate for the placement of
!B 		the outline curve.
!B
!C NOTE:
!C
!C	This script first sections a copy of the body at the given z value
!C	relative to the current workplane. It saves the part of the copy
!C	above the zvalue and then performs a body outline on the copy.
!C	This function may not work properly if the section creates multiple
!C	pieces.
!C
!# see also - htdocs/help.d/parasolids.htm


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

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


IF ARGC<2 THEN
 	Project_outline= WsTrue
ELSE
 	Project_outline= VAL(ARGV(1))
END IF


Stat= GLPlotOn
Start:!
ActivateUndo
Pkbody= WPKCurrentBody
IF NOT WPKIsEntity(Pkbody) THEN
        Stat=SetInputFormat("n4","")
        E1=WPKPickEntity("PICK BODY")
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT WPKIsEntity(E1) THEN Start
        Pkbody= WPKParentBody(E1)
END IF


Zlevel:!
stat= SetInputFormat("n4=","")
Stat= SetEqualsValue(Zvalue)
Stat=SetPickReturn(WsGeometryZ)
Zvalue=GetValue("Z VALUE OF SECTION",Answer$)
IF (ExitScript(Destination$)) THEN Leave
Stat=SetPickReturn(WsGeometryEnd)

IF Project_outline= WsTrue THEN
	stat= SetInputFormat("n4=","")
	Stat= SetEqualsValue(Zlevel)
	Stat=SetPickReturn(WsGeometryZ)
	Zlevel=GetValue("Z LEVEL OF OUTLINE CURVE",Answer$)
	IF (ExitScript(Destination$)) THEN Leave
	Stat=SetPickReturn(WsGeometryEnd)
END IF

PlotOff
WPKClearErrorFlag
Pc= PointXYZ(0,0,Zvalue)
Pkbody1= WPKCopyBody(Pkbody)
G1= WPKPlnSectionBody(Pkbody1,Pc,1)
Group= WPKBodyOutline(Pkbody1,Zlevel,Project_outline)
Stat= WPKDeleteBody(G1)
Stat= DeleteEntity(G1)
Stat= DeleteEntity(Pc)
PlotOn
Stat= PlotEntity(Group)

ActivateUndo
Stat= AdvanceUndoNumber("z body outline")
Stat= AddGroupToUndo(WsUBCreateMode,Group,0,WsTrue)
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck
Stat= DeleteEntity(Group)

GOTO Start

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