
! script name: pksurfaces.d/loftedents
! solids: construct a lofted body through a series of entities

!A
!A NAME:
!A
!A 	Lofted Entities
!A
!A DESCRIPTION:
!A
!A	This script will make a lofted body through a series of
!A	single entities.
!A
!B INSTRUCTIONS:
!B
!B
!B 	PICK ENTITY # , Proceed: Pick the entities in order. The pick on
!B				the entity determines the direction. 
!B
!C NOTES:
!C
!C	The pick location determines the direction of each entity.
!C	Each entity should be picked at the same end.
!C
!# see also - htdocs/help.d/parasolids.htm

Stat=ChangeLabelStr("ScriptNameStatus","Function: lofted entities ")

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")
Hold_Group=CreateGroup("TEMP1")

Ent_count=1
Solid_body= WsTrue
Pick_loop: !
Stat=SetInputFormat("a1",",P,")
Stat=SetPickMask(WsPickNoSurf)
E1=PickEntity("PICK ENTITY #"&VAL$(Ent_count)&", Proceed ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$="P" THEN Blend_ents
IF NOT ValidGeometry(E1) THEN Pick_loop

T= LastPickPara
Stat=SetPickMask(WsPickAll)
E2= CopyEntity(E1)
Stat= SetReverseDir(E2,WsFalse)
IF T> 0.5 THEN Stat= SetReverseDir(E2,WsTrue)
Stat= SetSelectedFlag(E2,WsTrue)
Stat= SetSelectedFlag(E1,WsTrue)
Stat= PlotEntity(E2)
Contour=CreateGroup("Contour")
Stat=AddToGroup(Hold_group,E1)
Stat=AddToGroup(Contour,E2)
Stat=AddToGroup(Group,Contour)
Solid_body= WsFalse
Ent_count=Ent_count+1
GOTO Pick_loop

Blend_ents: !
Stat= SetSelectedFlag(Hold_group,WsFalse)
Stat= PlotEntity(Hold_group)
Stat= DeleteEntity(Hold_group)
Grp_count=GroupCount(Group)
WPKClearErrorFlag
Pkbody=WPKLoftedBody(Group,Solid_body)
Stat=DeleteGroup(Group,WsTrue)

ActivateUndo
Stat= AdvanceUndoNumber("lofted body")
Stat= AddItemToUndo(WsUBPKSessionMark)
WPKErrorCheck

GOTO Blend_loop

Leave:!
Stat=DeleteGroup(Group,WsTrue)
Stat= SetSelectedFlag(Hold_group,WsFalse)
Stat= PlotEntity(Hold_group)
Stat=DeleteEntity(Hold_group)
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
