
! script name: surfaces.d/varentsweep
! 3dtopic: construct variable entity sweep

!A
!A NAME:
!A
!A 	Variable Entity Sweep
!A
!A DESCRIPTION:
!A
!A 	This script will make a variable cross section surface.  At every point
!A 	of the drive entity, a cross section is created which is a linear blend
!A 	of the starting and ending cross sections.  The starting and ending
!A 	cross sections must be placed at the start and end points respectively
!A 	of the drive entity.
!A
!B INSTRUCTIONS:
!B
!B 	U PATCH WIDTH: Enter the width of the patch to be used
!B 		along the cross section contours.
!B
!B 	V PATCH WIDTH: Enter the width of the patch to be used
!B 		along the drive contour.
!B
!B 	PICK DRIVE ENTITY: Pick the generating entity.
!B
!B 	PICK STARTING CROSS SECTION: Pick the constant cross section.
!B
!B 	PICK ENDING CROSS SECTION: Pick the constant cross section.
!B
!C NOTES:
!C
!C 	The starting and ending cross sections must have the same number of
!C 	elements.
!C
!C 	The patch widths need not match small radii. The surface will
!C 	automatically be created width a minimum number of patches on small
!C 	radii. Small splines however will require consideration in patch size.
!C
!C 	The optimum workplane for a variable cross section is the workplane of
!C 	the drive contour. Most other workplanes will give an equivalent
!C 	surface, but in some workplanes the surface may not be generated, or it
!C 	may give undesirable results.
!C
!C 	The drive entity must not ever become perpendicular to the workplane.
!C 	If this occurs the orientation of the cross section becomes confused.
!C
!C 	The U contours of the variable cross section surface are the cross
!C 	sections.  The V contours are the contours generated along the drive
!C 	contour.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: variable entity sweep ")

DIM Answer$[256]
DIM Destination$[256]

ActivateUndo
Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.5)

Uwidth=Patch_width
Vwidth=Patch_width
Blend_loop:!

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Uwidth)
Uwidth=GetValue("U PATCH WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Stat=SetEqualsValue(Vwidth)
Vwidth=GetValue("V PATCH WIDTH",Answer$)
IF ExitScript(Destination$) THEN Leave

Cont_count=1

Pick_loop: !
Stat=SetPickMask(WsPickNoSurf)
Drive_ent=PickEntity("PICK DRIVE ENTITY ")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Drive_ent) THEN Pick_loop
T1= LastPickPara
Dir1= (T1<= 0.5)*WsForward+ (T1> 0.5)*WsReverse


Pick_cross1: Stat=SetPickMask(WsPickNoSurf)
Cross_ent1=PickEntity("PICK STARTING CROSS SECTION ENTITY")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Cross_ent1) THEN Pick_cross1
T2= LastPickPara
Dir2= (T2<= 0.5)*WsForward+ (T2> 0.5)*WsReverse

Pick_cross2: Stat=SetPickMask(WsPickNoSurf)
Cross_ent2=PickEntity("PICK ENDING CROSS SECTION ENTITY")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Cross_ent2) THEN Pick_cross2
T3= LastPickPara
Dir3= (T3<= 0.5)*WsForward+ (T3> 0.5)*WsReverse


Surf=VarCrossSurface(Drive_ent,Cross_ent1,Cross_ent2,Uwidth,Vwidth,Dir1,Dir2,Dir3)

ActivateUndo
Stat= AdvanceUndoNumber("cross section  surface")
Stat= AddItemToUndo(WsUBCreateMode,Surf)

GOTO Blend_loop

Leave:!
Stat=SetPickMask(WsPickGeometry)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END
