
! script name: vpksoliddraft.d/vpkbodyoutline
! var_solids: generate the outline contour for a body.

!A
!A NAME:
!A
!A 	Body Outline  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script generates the outline of a body.
!A
!A~ image location - images/pkbodyoutline.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK BODY: Pick the body.
!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 is a new feature added in Parasolids Release 12.1. It still
!C	has some problems in that it sometimes fails to create the
!C	outline.
!C
!# see also - htdocs/help.d/parasolids.htm

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

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


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

ActivateUndo
Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave


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
Stat= EntityNameCheck(Pkbody,Body$)


Zlevel:!
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)
	No_z_var= LastVariableInput(Z_var$)
END IF


WPKClearErrorFlag
Stat= GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("SOLIDS: Body Outline")
IF No_z_var THEN
	V1= FreeParameter("Z level of outline",Zlevel)
ELSE
	V1= FreeParameter("Z level of outline",Z_var$)
END IF
V2= FreeParameter("Project outline",Project_outline)
Group= WPKBodyOutline(Body$,V1,V2)
Stat= AutoNameGroup(Group,Name$)
RecordFunctionOff
IF ValidGeometry(Group) THEN
        Stat= PlotEntity(Group)
        ActivateUndo
        Stat= AdvanceUndoNumber("body outline")
        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 Start

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