
! script name: pksurfaces.d/guidedloft
! solids: construct a lofted body with guide contours.

!A
!A NAME:
!A
!A 	Guided Loft
!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]

ActivateUndo
Active_workplane=0
Work=CurrentWorkplane
IF ValidGeometry(Work) THEN Active_workplane=1

Highlight_color= 2
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)

Stat= GLPlotOn
Blend_loop:!
StdWorkplane

Group=CreateGroup("TEMP")
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 ValidGeometry(Contour) THEN Pick_loop

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

Guide_contours:!
Guides=CreateGroup("TEMP")
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 ValidGeometry(Guide) THEN Guide_loop

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




Blend_ents: !
UnselectAll
WPKClearErrorFlag
Pkbody=WPKGuidedLoft(Group,Guides)
Stat=DeleteEntity(Group)
Stat=DeleteEntity(Guides)

ActivateUndo
Stat= AdvanceUndoNumber("guided loft")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

GOTO Blend_loop

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