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

!A
!A NAME:
!A
!A 	Lofted Body  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A	This script will make a lofted body through a series of
!A	contours having the same number of elements.
!A
!A~ image location - images/pkloftedbody.gif
!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: lofted body ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name$[256]
DIM Contour$[256]

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

Highlight_color= 2
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

Stat= GLPlotOn
Blend_loop:!

Group=CreateGroup("TEMP")

Cont_count=1
Solid_body= WsTrue
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)
Closed= IsContClosed(Contour)
IF NOT Closed THEN Solid_body= WsFalse
Stat= SetSelectedFlag(Contour,WsTrue)
Cont_count=Cont_count+1
GOTO Pick_loop

Blend_ents: !
Grp_count=GroupCount(Group)
IF Solid_body THEN
	Solid_body= WsFalse
        Stat=SetInputFormat("a1=",",1,2,")
        Stat=SetEqualsValue(0,"Solid")
        Stat=GetValue("BODY TYPE:  ( 1 ) solid  ( 2 ) sheet ",Answer$)
        IF ExitScript(Destination$) THEN Leave
        IF Answer$= "1" THEN Solid_body= WsTrue
END IF


UnselectAll
WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("LOFT: Contour loft")
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
V1= FreeParameter("Solid body",Solid_body)
Pkbody=WPKLoftedBody(G1,V1)
Stat= WPKNameBody(Pkbody,Name$)
Stat= WPKSetBodyParent(Pkbody)
Stat= DeleteEntity(G1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat=DeleteEntity(Group)
Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("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
