
! script name: vsplines.d/csentgroup
! var_topic: construct cubic spline through an existing group of points

!A
!A NAME:
!A
!A 	Cubic Spline Entity through group  VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a cubic spline through a group of points.
!A 	A cubic spline maintains tangency between the points and approximate
!A 	continuity of the curvature.
!A
!A~ image location - images/csplinecurve.jpg
!B INSTRUCTIONS:
!B
!B	PICK GROUP OF POINTS: Pick the group of points to pass the
!B	cubic spline through.
!B

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

DIM Answer$[256]
DIM Destination$[256]
DIM Group$[256]
DIM Name$[256]
DEG

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

ActivateUndo
Group_loop:!


Group= PickGroupEnt("PICK GROUP OF POINTS")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Group) THEN Group_loop
Stat= EntityNameCheck(Group,Group$)

Stat= GenerateVarName(WsCSplineCurveEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("SPLINE: cubic spline curve ")
Stat= SetRecDelLastExec
Group1=PtsInGroup(Group$,WsPickPoints)
Ps= GroupElement(Group1,1)
Pe= GroupElement(Group1,GroupCount(Group1))
Spline_ent=CSCurvePtGrp(Group1,Ps,0,Pe,0)
Stat=DeleteEntity(Group1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Spline_ent) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("cubic spline")
	Stat= AddItemToUndo(WsUBCreateMode,Spline_ent)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Group_loop


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

