

! script name: vsplines.d/beziergroup
! var_topic: Sample - construct bezier curve through given group of points

!A
!A NAME:
!A
!A 	Bezier pt group   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a bezier curve using a group of points
!A 	as control points.
!A
!A 	A bezier curve is a polynomial, the degree of the polynomial is
!A 	equal to the number of points minus one, and is tangent at both
!A 	ends of the curve, and is influenced by the weight of the other
!A 	points.
!A
!A~ image location - images/beziercurve.jpg
!B INSTRUCTIONS:
!B
!B 	PICK GROUP OF POINTS: Pick the group of points.
!B 		The spline curve will use the points in the order
!B 		they appear in the group.
!B
!B NOTES:
!B
!B 	Enter the last point twice to end the point input mode.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: bezier 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(WsBSplineEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("SPLINE: bezier curve ")
Stat= SetRecDelLastExec
Group1=PtsInGroup(Group$,WsPickPoints)
Ps= GroupElement(Group1,1)
Pe= GroupElement(Group1,GroupCount(Group1))
Spline_ent=BSplinePtGrp(Group1,0,3)
Stat=DeleteEntity(Group1)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord
IF NOT ValidGeometry(Spline_ent) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("bezier curve")
	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

