
! script name: vpkswept.d/vpkextcont2bdys
! var_solids: construct body by extruding a contour between two bodies

!A
!A NAME:
!A
!A 	Extrude Contour Between Bodies  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script will extrude a contour between two bodies.
!A
!A~ image location - images/pkextrudebetween.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR TO BE EXTRUDED: Select the
!B 		contour to be extruded.  The contour must be located
!B 		between the two bodies.  It must be a synergy contour.
!B
!B 	PICK START BOUNDING BODY: Pick the first
!B 		bounding body to be encountered in the
!B 		direction of the extrusion.
!B
!B 	PICK END BOUNDING BODY: Pick the last
!B 		bounding body encountered.
!B
!B	PICK DIRECTION LINE: Into or Above workplane, Vector:
!B 		Either pick a line to determine the direction or 
!B 		I will extrude into the current workplane(Z-)
!B 		A will extrude above the current workplane(Z+)
!B
!C NOTES:
!C
!C 	The direction must go from the start bound to the end bound.
!C
!C 	The result is a separate body from the bounding body.
!C 	If you wish to have only one body then use unite bodies.
!C
!C 	The extruded body must totally intersect the bounding bodies.
!C 	A partial intersection will result in an error.
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: extrude contour between two bodies")

DIM Destination$[256]
DIM Answer$[256]
DIM Name$[256]
DIM Body1$[256]
DIM Body2$[256]
DIM Contour$[256]
DIM Axis_line$[256]
DIM Xshift_var$[256]
DIM Yshift_var$[256]
DIM Zshift_var$[256]

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


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

Closed= IsContClosed(Contour)
Solid_body= WsFalse
IF NOT Closed THEN
	Stat=SetInputFormat("a1=",",P,")
	Stat=SetEqualsValue(0,"Solid")
	Stat=GetValue("CAN ONLY EXTRUDE CLOSED CONTOUR ",Answer$)
	IF ExitScript(Destination$) THEN Leave
	GOTO Pick_contour
END IF
Stat= EntityNameCheck(Contour,Contour$)
Solid_body= WsTrue

Pick_body1:!
E1=WPKPickEntity("PICK START BOUNDING BODY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E1) THEN Pick_body1

Body_type= WPKBodyType(E1)
IF (Body_type= WsPKWireBody) THEN Pick_body1
Pkbody1= WPKParentBody(E1)
Stat= EntityNameCheck(Pkbody1,Body1$)


Pick_body2:!
E2=WPKPickEntity("PICK END BOUNDING BODY")
IF (ExitScript(Destination$)) THEN Leave
IF NOT WPKIsEntity(E2) THEN Pick_body2

Body_type= WPKBodyType(E2)
IF (Body_type= WsPKWireBody) THEN Pick_body2
Pkbody2= WPKParentBody(E2)
Stat= EntityNameCheck(Pkbody2,Body2$)


Pick_line:! 
Stat=SetInputFormat("a1",",I,A,V,")
L1=PickEntity("PICK DIRECTION LINE, Into or Above workplane, Vector ",Answer$)
IF ExitScript(Destination$) THEN Leave
SELECT Answer$
CASE "I"
        Xshift=0
        Yshift=0
        Zshift= -1
        No_xshift_var=1
        No_yshift_var=1
        No_zshift_var=1
        Make_line=1
CASE "A"
        Xshift=0
        Yshift=0
        Zshift= 1
        No_xshift_var=1
        No_yshift_var=1
        No_zshift_var=1
        Make_line=1
CASE "V"
        Stat=SetInputFormat("n4=","")
        Stat=SetDepthEquals(Xshift)
        Xshift=InputDepth("X SHIFT")
        IF ExitScript(Destination$) THEN Leave
        No_xshift_var= LastVariableInput(Xshift_var$)

        Stat=SetInputFormat("n4=","")
        Stat=SetDepthEquals(Yshift)
        Yshift=InputDepth("Y SHIFT")
        IF ExitScript(Destination$) THEN Leave
        No_yshift_var= LastVariableInput(Yshift_var$)

        Stat=SetInputFormat("n4=","")
        Stat=SetDepthEquals(Zshift)
        Zshift=InputDepth("Z SHIFT")
        IF ExitScript(Destination$) THEN Leave
        No_zshift_var= LastVariableInput(Zshift_var$)
        Make_line=1
CASE ELSE
        IF NOT ValidDependency(L1) THEN Pick_line
        Etype= EntityType(L1)
        IF Etype<> WsLineEnt THEN Pick_body
        Pick_para= LastPickPara
        Stat= EntityNameCheck(L1,Axis_line$)
        Make_line=0
END SELECT

WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("SOLID: Extrude contour")
IF Make_line THEN
        IF No_xshift_var THEN
                V1= FreeParameter("X shift",xshift)
        ELSE
                V1= FreeParameter("X shift",Xshift_var$)
        END IF
        IF No_yshift_var THEN
                V2= FreeParameter("Y shift",yshift)
        ELSE
                V2= FreeParameter("Y shift",Yshift_var$)
        END IF
        IF No_zshift_var THEN
                V3= FreeParameter("Z shift",zshift)
        ELSE
                V3= FreeParameter("Z shift",Zshift_var$)
        END IF
        P1= PointXYZ(0,0,0)
        P2= PointXYZ(V1,V2,V3)
        L1= LineTwoPoints(P1,P2,WsTrimmed)
        Stat= DeleteEntityList(P1,P2)
ELSE
        L1= CopyEntity(Axis_line$)
        IF Pick_para< 0.5 THEN
                Stat= ReverseEnt(L1)
        END IF
END IF
Pkbody=WPKExtrudeContour(Contour$,Body1$,Body2$,L1,WsTrue)
Stat= WPKNameBody(Pkbody,Name$)
Stat= WPKSetBodyParent(Pkbody)
Stat= DeleteEntity(L1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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


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