
! script name: surfaces.d/nurbblend
! 3dtopic: script for making a nurb surface

!A
!A NAME:
!A
!A 	NURBS: Equal Elements
!A
!A DESCRIPTION:
!A
!A 	This script will make a NURBS surface.  There must be the same number
!A 	of elements on each section.
!A
!B INSTRUCTIONS:
!B
!B 	PATCH WIDTH: Enter the width of the patch to be used.
!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 	The patch width is automatically adjusted for small radii.
!c
!C 	NURBS are influenced by cross sections, but may not actually pass
!C 	through any of the cross sections.
!C

Stat=ChangeLabelStr("ScriptNameStatus","Function: nurb blend ")

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

ActivateUndo
Bezier_surf= WsFalse
IF ARGC<2 THEN
        Bezier_surf= WsFalse
ELSE
        Bezier_surf= VAL(ARGV(1))
END IF

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

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

Blend_loop:!

StdWorkplane

Group=CreateGroup("TEMP")

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

Cont_count=1
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 ValidGeometry(Contour) THEN Pick_loop

Stat=Highlight(Contour,WsPickPen,WsDirArrowOff)
Stat=AddToGroup(Group,Contour)
Cont_count=Cont_count+1
GOTO Pick_loop

Blend_ents: !
Grp_count=GroupCount(Group)
Surf1=EqualElementSurf(WsNurbSurfEnt,Group,"BLEND",Patch_width,Bezier_surf)

ActivateUndo
Stat= AdvanceUndoNumber("nurb surface")
Stat= AddItemToUndo(WsUBCreateMode,Surf1)

Stat=DeleteEntity(Group)

GOTO Blend_loop

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