
! script name: vpoints.d/arclenpts
! var_topic: generate points along contour at equal arc length intervals

!A
!A NAME:
!A
!A 	Equal Arc Length Contour Points VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will generate points along a contour at equal arc
!A 	length intervals.
!A
!A~ image location - images/arclenpts.jpg
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR: Pick the contour to generate the points along.
!B
!B 	NUMBER OF POINTS, Distance: Input the number of points.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: equal arc length contour points ")

DIM Destination$[256]
DIM Answer$[256]
DIM Contour$[256]
DIM Name$[256]
DIM Num_var$[256]
DIM Dist_var$[256]

Var_object= CheckVarObject
IF ExitScript(Destination$) THEN Leave

ActivateUndo
Num_pts= 10
Dist=NamedVarVal("parallel distance",WsSystemVars,.25)

Pick_loop:!
Contour=PickGroupEnt("PICK CONTOUR")
IF ExitScript(Destination$) THEN Leave
IF NOT ValidGeometry(Contour) THEN Pick_loop
IF NOT ValidDependency(Contour) THEN Pick_loop
Stat= EntityNameCheck(Contour,Contour$)

Stat=Highlight(Contour,WsPickPen,WsDirArrowsOff)

stat= SetInputFormat("n0=a1",",D,")
stat= SetEqualsValue(Num_pts)
Num_pts= GetValue("NUMBER OF SECTIONS, Distance ",Answer$)
IF ExitScript(Destination$) THEN Leave
IF Answer$<> "D" THEN
	No_num_var= LastVariableInput(Num_var$)

	Stat= GenerateVarName(WsGroupEnt,Name$)
	RecordFunctionOn
	Stat= RecordDescr("POINT: Points along contour")
	Stat= SetRecDelLastExec
	IF No_num_var THEN
       		 V1= FreeParameter("Number points",Num_pts)
		Group=ArcLengthPts(Contour$,V1)
	ELSE
		Group=ArcLengthPts(Contour$,Num_var$)
	END IF
	Stat= AutoNameGroup(Group,Name$)
	RecordFunctionOff
	CloseVarRecord
	IF NOT ValidGeometry(Group) THEN
       		 DelLastVarRecord
	END IF
ELSE

stat= SetInputFormat("n4=","")
stat= SetEqualsValue(Dist)
Dist= GetValue("DISTANCE BETWEEN POINTS ",Answer$)
IF ExitScript(Destination$) THEN Leave
No_dist_var= LastVariableInput(Dist_var$)
	Stat= GenerateVarName(WsGroupEnt,Name$)
        RecordFunctionOn
        Stat= RecordDescr("POINT: Points along contour")
	Stat= SetRecDelLastExec
        IF No_dist_var THEN
                V1= FreeParameter("Distance",Dist)
                Group=ArcLengthPts(Contour$,1,V1)
        ELSE
                Group=ArcLengthPts(Contour$,1,Dist_var$)
        END IF
        Stat= AutoNameGroup(Group,Name$)
        RecordFunctionOff
	Curr_record= CurrentVarRecord
        CloseVarRecord
        IF NOT ValidGeometry(Group) THEN
                DelLastVarRecord
	ELSE
		ActivateUndo
		Stat= AdvanceUndoNumber("arclength pts")
		Stat= AddGroupToUndo(WsUBCreateMode,Group,1,WsFalse)
		Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
	END IF
END IF

Stat= PlotEntity(Contour$)
GOTO Pick_loop

Leave:!
Vdist=CreateVariable("parallel distance",WsSystemVars,Dist)
stat= SetInputFormat("n4=","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
