
! script name: vpksolids.d/vpkwrappedloft
! var_solids: construct a lofted body through a series of wrapped profiles

!A
!A NAME:
!A
!A 	Wrapped Lofted Body  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script will make a lofted body through a series of
!A	wrapped contours having the same number of elements.
!A
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR # , Proceed: Pick the contours in order.
!B 		The actual point picked on the contour determines
!B 		the direction of the surface created.
!B
!C NOTES:
!C
!C 	The surface is created by blending the sections in order, element by
!C 	element.  The first element of section 1 to the first element of
!C 	section 2, the second element of section 1 to the second element of
!C 	section 2, and so forth.
!C		
!C	If there are only two closed contours they can be made into a solid
!C	body. Otherwise it will become a sheet body.
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: wrapped lofted body ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Contour$[256]
DIM Radius_var$[256]
DIM Astart_var$[256]
DIM Taper_var$[256]


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

Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)
Highlight_color= 2
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

Stat= GLPlotOn
Blend_loop:!
Stat=SetInputFormat("a1=",",X,Y,Z,")
Stat=SetEqualsValue(0,"X")
Stat=GetValue("WRAP ABOUT: X axis, Y axis,or Z axis",Answer$)
IF ExitScript(Destination$) THEN Leave
Wnich_axis=1
IF Answer$="X" THEN Which_axis=1
IF Answer$="Y" THEN Which_axis=2
IF Answer$="Z" THEN Which_axis=3

Stat=SetInputFormat("a1=",",W,C,")
Ask_radius:Stat=SetInputFormat("n4=","")
Radius=InputRadius("RADIUS OF CYLINDER")
IF (ExitScript(Destination$)) THEN Leave
No_radius_var= LastVariableInput(Radius_var$)
C1= LastPickEnt
IF ValidGeometry(C1) THEN
        IF NOT ValidDependency(C1) THEN Ask_radius
        No_radius_var=0
        Stat= EntityNameCheck(C1,Radius_var$)
END IF

Astart=InputAngle("STARTING ANGLE")
IF ExitScript(Destination$) THEN Leave
No_astart_var= LastVariableInput(Astart_var$)

Stat= SetAngleEquals(Taper)
Taper=InputAngle("TAPER ANGLE")
IF ExitScript(Destination$) THEN Leave
No_taper_var= LastVariableInput(Taper_var$)


Group=CreateGroup("TEMP")
Cont_count=1
Pick_loop: !
Stat=SetInputFormat("a1",",P,")
Stat=SetPickMask(WsPickNoSurf)
Contour=PickGroupEnt("PICK CONTOUR #"&VAL$(Cont_count)&", Proceed ",0,Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN Blend_ents
IF NOT ValidDependency(Contour) THEN Pick_loop

Stat=SetPickMask(WsPickAll)
Stat=Highlight(Contour,WsPickPen,WsDirArrowOff)
Stat=AddToGroup(Group,Contour)
Stat= SetSelectedFlag(Contour,WsTrue)
Cont_count=Cont_count+1
GOTO Pick_loop

Blend_ents: !
Grp_count=GroupCount(Group)

UnselectAll
WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("LOFT: Wrapped Contours")
G1= CreateGroup("contours")
FOR I=1 TO Grp_count
        RecordFunctionOff
        E1= GroupElement(Group,I)
        Stat= EntityNameCheck(E1,Contour$)
        IF ValidDependency(E1) THEN
                RecordFunctionOn
                Stat= AddToGroup(G1,Contour$)
                RecordFunctionOff
        END IF
NEXT I
RecordFunctionOn
IF No_astart_var THEN
        V2= FreeParameter("Astart",Astart)
ELSE
        V2= FreeParameter("Astart",Astart_var$)
END IF
IF No_taper_var THEN
        V3= FreeParameter("Taper",Taper)
ELSE
        V3= FreeParameter("Taper",Taper_var$)
END IF
V4= FreeParameter("Tolerance",Tol)
Work=CurrentWorkplane
RecordFunctionOff
IF Which_axis=1 THEN
RecordFunctionOn
P1=PointXYZ(0,0,0)
P2=PointXYZ(0,1,0)
P3=PointXYZ(-1,0,0)
Trans1=ThreePtTrans(P1,P2,P3)
Stat=SetWorkplane(Trans1)
Stat=DeleteEntityList(P1,P2,P3)
END IF
RecordFunctionOff
IF Which_axis=2 THEN
RecordFunctionOn
P1=PointXYZ(0,0,0)
P2=PointXYZ(1,0,0)
P3=PointXYZ(0,1,0)
Trans1=ThreePtTrans(P1,P2,P3)
Stat=SetWorkplane(Trans1)
Stat=DeleteEntityList(P1,P2,P3)
END IF
RecordFunctionOff
IF Which_axis=3 THEN
RecordFunctionOn
P1=PointXYZ(0,0,0)
P2=PointXYZ(1,0,0)
P3=PointXYZ(0,0,1)
Trans1=ThreePtTrans(P1,P2,P3)
Stat=SetWorkplane(Trans1)
Stat=DeleteEntityList(P1,P2,P3)
END IF
RecordFunctionOn
IF No_radius_var THEN
        V1= FreeParameter("Radius",Radius)
        Pkbody=WPKWrapLoftBody(G1,V1,V2,V3,V4)
ELSE
        Pkbody=WPKWrapLoftBody(G1,Radius_var$,V2,V3,V4)
END IF
Stat= WPKNameBody(Pkbody,Name$)
Stat= WPKSetBodyParent(Pkbody)
Stat= DeleteEntity(G1)
Stat=SetWorkplane(Work)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat=DeleteEntity(Group)
Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("wrapped lofted body")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck

GOTO Blend_loop

Leave:!
UnselectAll
Stat=DeleteEntity(Group)
Stat=SetPickMask(WsPickAll)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
