
! script name: 3dextend.d/cedgevector
! var_topic: extend edge curve with bicubic surface at specified vector

!A
!A NAME:
!A
!A 	Vector Extend Edge: Bicubic	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will create a new bicubic surface by extending the edge
!A 	of the surface the specified distance, with the XYZ shift.
!A
!B INSTRUCTIONS:
!B
!B 	X SHIFT: Enter the amount of X shift.
!B
!B 	Y SHIFT: Enter the amount of Y shift.
!B
!B 	Z SHIFT: Enter the amount of Z shift.
!B
!B 	PATCH WIDTH ALONG EDGES: Enter the width of the patch to be used along
!B 		the edge.
!B
!B 	PICK EDGE CURVE ON SURFACE: Pick the edge curve on surface.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: cubic: edge vector extension")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[80]
DIM Surface$[256]
DIM X_var$[256]
DIM Y_var$[256]
DIM Z_var$[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(Xshift)
Xshift= GetValue("X SHIFT",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_x_var= LastVariableInput(x_var$)

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Yshift)
Yshift= GetValue("Y SHIFT",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_y_var= LastVariableInput(y_var$)

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Zshift)
Zshift= GetValue("Z SHIFT",Answer$)
IF (ExitScript(Destination$)) THEN Leave
No_z_var= LastVariableInput(z_var$)

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
Patch_width= V_width

Intersect2:!
Pick_loop:!
Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n4","")
Surface=PickEntity("PICK EDGE CURVE ON SURFACE ")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Surface) THEN Pick_loop
Stat= EntityNameCheck(Surface,Surface$)

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

Stat= SetPickMask(WsPickGeometry)

Para_value1= 0.0


Stat= GenerateVarName(WsCubicSurfEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("BICUBIC: Vector edge extension")
Stat= SetRecDelLastExec
Stat= Set3dInterOffset(0.0)
V1= FreeParameter("Which edge",Which1)
V2= FreeParameter("Direction",Dir1)
V3= FreeParameter("Tolerance",Tol)
IF No_x_var THEN
        V4= FreeParameter("Xshift",Xshift)
ELSE
        V4= FreeParameter("Xshift",X_var$)
END IF
IF No_y_var THEN
        V5= FreeParameter("Yshift",Yshift)
ELSE
        V5= FreeParameter("Yshift",Y_var$)
END IF
IF No_z_var THEN
        V6= FreeParameter("Zshift",Zshift)
ELSE
        V6= FreeParameter("Zshift",Z_var$)
END IF
IF No_patch_var THEN
        V7= FreeParameter("Patch width",Patch_width)
ELSE
        V7= FreeParameter("Patch width",Patch_var$)
END IF
Shift_vector= PointXYZ(V4,V5,V6)
S1=EdgeExtendSurf(WsVector,WsCubicSurfEnt,Surface$,V1,V2,Shift_vector,V7,V7,V3,Para_value)
Stat= NameEntity(S1,Name$)
Stat= DeleteEntity(Shift_vector)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(S1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("cubic ext surf")
	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)

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


Leave:!
stat= SetInputFormat("n4","")
Stat= SetPickMask(WsPickGeometry)
stat= DeleteEntity(Shift_vector)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
