
! script name: var_fillet.d/nblendedges
! var_topic: nurb blend surface between the edges of two surfaces

!A
!A NAME:
!A
!A 	Blend: NURB Edge
!A
!A DESCRIPTION:
!A
!A 	This script will create a nurb surface.  The surface is created by
!A 	using the flow curves of the selected edges of the surfaces to generate
!A 	a blend surface.  The blend surface is created in such a way as to be
!A 	tangent to the original surfaces.
!A
!B INSTRUCTIONS:
!B
!B 	PATCH WIDTH ALONG EDGES: Enter the width of the patch to be used
!B 		along the edge.
!B
!B 	PICK EDGE ON SURFACE #1: Pick the first surface near the edge to be 
!B 		used in creating the nurb blend surface.
!B
!B 	PICK EDGE ON SURFACE #2: Pick the other surface near the edge to be 
!B 		used in creating the nurb blend surface.
!B
!C NOTES:
!C
!C 	The edges should be picked so directions are consistent.
!C 	The starting location will be the end nearest the pick point.  The
!C 	pick point must be a point on the edge curve and should be as close
!C 	as possible to the starting location.
!C
!C 	The "3D Fillet Tol" should be left at its default value unless problems
!C 	occur.  If a problem is encountered, then go to a smaller tolerance.
!C 	If small parts are the normal, then consider changing the default
!C 	tolerance.  The tolerance may be edited temporarily by selecting the
!C 	Variables option in the Settings menu, the tolerance may be changed
!C 	permanently by selecting the Constants option in the Settings menu.
!C

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

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[80]
DIM Name1$[256]
DIM Name2$[256]
DIM Name$[256]
DIM Patch_var$[256]

Var_object= CheckVarObject
IF (ExitScript(Destination$)) THEN Leave


ActivateUndo
Patch_width=NamedVarVal("3D Default Patch",Ws3DSystemVars,0.25)
Tol=NamedVarVal("3D Fillet Tol",Ws3DSystemVars,0.005)

Start:!

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Patch_width)
V_width=GetValue("PATCH WIDTH ALONG EDGES",Answer$)
IF ExitScript(Destination$) THEN Leave
No_patch_var= LastVariableInput(Patch_var$)
U_width=V_width

Intersect2:!
Pick_surf1:!
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n0","")
Surface=PickEntity("PICK EDGE ON SURFACE #1",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Surface) THEN Pick_surf1
Stat= EntityNameCheck(Surface,Name1$)
Surface1=Surface

GOSUB Which_edge
IF NOT Surf_edge THEN Pick_surf1
Which1=Surf_edge
Dir1=Edge_dir

Pick_surf2:!
Stat=SetPickMask(WsPickSurfOnly)
Stat=SetInputFormat("n0","")
Surface=PickEntity("PICK EDGE ON SURFACE #2",Answer$)
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(Surface) THEN Pick_surf2
Stat= EntityNameCheck(Surface,Name2$)
Surface2=Surface

GOSUB Which_edge
IF NOT Surf_edge THEN Pick_surf2
Which2=Surf_edge
Dir2=Edge_dir

Stat=SetPickMask(WsPickGeometry)

Weight1=0.3
Weight2=0.3
Para_value1=0.0
Para_value2=0.0

Stat= GenerateVarName(WsNurbSurfEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("NURB BLEND: Edges")
V1= FreeParameter("Which edge 1",Which1)
V2= FreeParameter("Which edge 2",Which2)
V3= FreeParameter("Weight 1",Weight1)
V4= FreeParameter("Weight 2",Weight2)
V5= FreeParameter("Direction 1",Dir1)
V6= FreeParameter("Direction 2",Dir2)
IF No_patch_var THEN
        V7= FreeParameter("Patch width",Patch_width)
ELSE
        V7= FreeParameter("Patch width",Patch_var$)
END IF
V8= FreeParameter("Tolerance",Tol)

S1=BlendSurfaces(WsNurbSurfEnt,Name1$,V1,V5,V3,Name2$,V2,V6,V4,V7,V7,V8,Para_value1,Para_value2)
Stat= NameEntity(S1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(S1) THEN
	DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("nurb blend")
	Stat= AddItemToUndo(WsUBCreateMode,S1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Intersect2

Which_edge: Surf_edge=0
Edge_dir=WsForward
Pt=LastUVSurfPick(Surface)
IF NOT ValidGeometry(Pt) THEN RETURN
U=XPointValue(Pt)
V=YPointValue(Pt)
Stat=DeleteEntity(Pt)
Surf_edge=ClosestSurfEdge(Surface,U,V)

SELECT Surf_edge
    CASE 1,3
	Edge_dir=WsForward
	IF U>0.5 THEN Edge_dir=WsReverse
    CASE 2,4
	Edge_dir=WsForward
	IF V>0.5 THEN Edge_dir=WsReverse
END SELECT
RETURN 

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