
! script name: vpksolids.d/vpkcontourcut
! var_solids: construct block from a contour

!A
!A NAME:
!A
!A 	Contour Cut VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	Cuts a contour shaped opening out of a solid body. This function 
!A	is equivalent to making a contour block and subtracting it from
!A	the solid body. It may also be used to make a contour shaped
!A	hole in a sheet body.
!A
!A~ image location - images/pkcontourcut.gif
!A
!B INSTRUCTIONS:
!B
!B	PICK BODY: Pick the body to be cut from. It may be a solid
!B 		or a sheet body.
!B
!B	PICK CONTOUR: Pick the contour to be used. If not closed it
!B 		will close automatically.
!B
!B	HEIGHT ABOVE CONTOUR: Enter the height above the contour.
!B
!B	DEPTH BELOW CONTOUR: Enter the depth below the contour. Enter a
!B 		positive number.
!B
!C NOTES:
!C
!C	The contour must be contained in a plane.
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: Contour Cut")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Contour$[256]
DIM Body$[256]
DIM Height_var$[256]
DIM Depth_var$[256]

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

Stat= GLPlotOn

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

Pick_contour:!
Contour=PickGroupEnt("PICK CONTOUR ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Contour) THEN Pick_contour
Stat= EntityNameCheck(Contour,Contour$)

Stat=SetInputFormat("n4=","")
Stat=SetDepthEquals(Height1)
Height1=InputDepth("HEIGHT ABOVE CONTOUR")
IF ExitScript(Destination$) THEN Leave
No_height_var= LastVariableInput(Height_var$)

Stat=SetInputFormat("n4=","")
Stat=SetDepthEquals(Depth1)
Depth1=InputDepth("DEPTH BELOW CONTOUR")
IF ExitScript(Destination$) THEN Leave
No_depth_var= LastVariableInput(Height_var$)

WPKClearErrorFlag
RecordFunctionOn
Stat= RecordDescr("BODY: Contour cut")
IF No_height_var THEN
        V1= FreeParameter("Height",Height1)
ELSE
        V1= FreeParameter("Height",Height_var$)
END IF
IF No_depth_var THEN
        V2= FreeParameter("Depth",Depth1)
ELSE
        V2= FreeParameter("Depth",Depth_var$)
END IF
PlotOff
Pkcutbody=WPKContourBlock(Contour$,V1,V2)
G1= WPKSubtractBodies(Body$,Pkcutbody)
Stat= WPKNameBodyGroup(G1,Body$)
Stat= WPKSetBodyParent(G1,1)
Stat= DeleteEntity(G1)
PlotOn
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= WPKUpdateBody(Body$)

Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("contour cut")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
GOTO Pick_contour


Leave:!
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
