
! script name: vsplines.d/blendcspline
! var_topic: cubic spline blend between two points on two entities

!A
!A NAME:
!A
!A 	Cubic Spline Blend	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script blends a cubic spline (cspline) between two points on
!A 	two entities.
!A
!A~ image location - images/csplineblend.jpg
!B INSTRUCTIONS:
!B
!B 	PICK FIRST ENTITY: Pick the first entity
!B 		to be used for the cspline blend.
!B
!B 	PICK SECOND ENTITY: Pick the second entity
!B 		to be used for the cspline blend.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: cubic spline blend ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name1$[256]
DIM Name2$[256]
DIM Name$[256]
DEG

Highlight_color= 3
Stat= SetDefaults(WsSelectedEntPen,Highlight_color)
Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Spline_loop:!

Pick1:E1=PickEntity("PICK FIRST ENTITY")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E1) THEN Pick1
Stat= EntityNameCheck(E1,Name1$)
T1=LastPickPara
U1= 0.0*(T1<= 0.50)+ 1.0*(T1> 0.5)
Stat= SetSelectedFlag(E1,WsTrue)
Stat= PlotEntity(E1)

Pick2:E2=PickEntity("PICK SECOND ENTITY")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidDependency(E2) THEN Pick2
Stat= EntityNameCheck(E2,Name2$)
T2=LastPickPara
U2= 0.0*(T2<= 0.50)+ 1.0*(T2> 0.5)
Stat= SetSelectedFlag(E2,WsTrue)
Stat= PlotEntity(E2)

Stat= GenerateVarName(WsCSplineEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("CUBIC SPLINE: Blend")
Stat= SetRecDelLastExec

Dirpt1=ParameterPt(Name1$,T1)
Ps=ParameterPt(Name1$,U1)
Dirpt2=ParameterPt(Name2$,T2)
Pe=ParameterPt(Name2$,U2)
S1=CSplineTwoEnt(Name1$,Ps,Dirpt1,1,Name2$,Pe,Dirpt2,1)
Stat=DeleteEntity(Dirpt1)
Stat=DeleteEntity(Dirpt2)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat= NameEntity(S1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(S1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("cubic spline")
	Stat= AddItemToUndo(WsUBCreateMode,S1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
ActivateUndo
Stat= AdvanceUndoNumber("cubic spline")
Stat= AddItemToUndo(WsUBCreateMode,S1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
GOTO Spline_loop

Leave:!
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)
Stat=DeleteEntity(Dirpt1)
Stat=DeleteEntity(Dirpt2)
Stat= SetSelectedFlag(E1,WsFalse)
Stat= PlotEntity(E1)
Stat= SetSelectedFlag(E2,WsFalse)
Stat= PlotEntity(E2)
IF NOT LEN(Destination$) THEN
	LOAD "typecontrol"
ELSE
	LOAD Destination$
END IF
END

