
! script name: vpksolids.d/vpkguidedloft
! var_solids: construct a lofted body with guide contours.

!A
!A NAME:
!A
!A 	Guided Loft  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 series
!A	of guiding contours may be specified.
!A
!A~ image location - images/pkguidedloft.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK PROFILE # , Proceed: Pick the profile contours in order.
!B
!B 	PICK GUIDE # , Proceed: Pick the guide contours in order.
!B
!C NOTES:
!C
!C	The profile contours must be drawn in the same direction.
!C
!C	The profile contours must all have the same number of elements.
!C
!C	The profile contours must have an entity endpoint at the places
!C	where the guide contours intersect.
!C
!C	There does not need to be a guide contour at every entity
!C	endpoint on the profiles.
!C
!C	The guide contours must be drawn in the same direction.
!C
!C	The guide contours must touch each profile at the corresponding
!C	endpoint. That is if a guide contour intersects the first
!C	profile at the third entity endpoint, then it must intersect
!C	all profiles at the third entity endpoint.
!C
!C	The guide contours do not need to have the same number of elements.
!C
!C	The guide contours must have an entity endpoint whereever they
!C	intersect the profile contours.
!C
!C	The guide contours must be smooth. They cannot have any sharp
!C	corners.
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: guided loft ")

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("PROFILES")
Cont_count=1
Pick_loop: !
Stat=SetInputFormat("a1",",P,")
Stat=SetPickMask(WsPickNoSurf)
Contour=PickGroupEnt("PICK PROFILE #"&VAL$(Cont_count)&", Proceed ",0,Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN Guide_contours
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

Guide_contours:!
Guides=CreateGroup("GUIDES")
Guide_count=1
Guide_loop: !
Stat=SetInputFormat("a1",",P,")
Stat=SetPickMask(WsPickNoSurf)
Guide=PickGroupEnt("PICK GUIDE #"&VAL$(Guide_count)&", Proceed ",0,Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN Blend_ents
IF NOT ValidDependency(Guide) THEN Guide_loop

Stat=SetPickMask(WsPickAll)
Stat=Highlight(Guide,WsPickPen,WsDirArrowOff)
Stat=AddToGroup(Guides,Guide)
Stat= SetSelectedFlag(Guide,WsTrue)
Guide_count=Guide_count+1
GOTO Guide_loop


Blend_ents: !
Cont_count= GroupCount(Group)
Guide_count= GroupCount(Guides)

UnselectAll
WPKClearErrorFlag
Stat= GenerateVarName("Body",Name$)
RecordFunctionOn
Stat= RecordDescr("LOFT: guided loft")
G1= CreateGroup("profiles")
FOR I=1 TO Cont_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
G2= CreateGroup("guides")
FOR I=1 TO Guide_count
        RecordFunctionOff
        E1= GroupElement(Guides,I)
        Stat= EntityNameCheck(E1,Contour$)
        IF ValidDependency(E1) THEN
                RecordFunctionOn
                Stat= AddToGroup(G2,Contour$)
                RecordFunctionOff
        END IF
NEXT I
RecordFunctionOn
Pkbody=WPKGuidedLoft(G1,G2)
Stat= WPKNameBody(Pkbody,Name$)
Stat= WPKSetBodyParent(Pkbody)
Stat= DeleteEntity(G1)
Stat= DeleteEntity(G2)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= DeleteEntity(Group)
Stat= DeleteEntity(Guides)
Stat= WPKSolidRecordOn(Curr_record)
ActivateUndo
Stat= AdvanceUndoNumber("guided loft")
Stat= AddItemToUndo(WsUBPKSessionMark)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
WPKErrorCheck
GOTO Blend_loop

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