
! script name: vcontours.d/contlenseg
! var_topic: create a segment of a contour using arclength

!A
!A NAME:
!A
!A 	Contour Length Segment		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script creates a segment contour of a contour based on arclength.
!A
!B INSTRUCTIONS:
!B
!B 	PICK CONTOUR: Pick an element on the contour.
!B
!B 	START LENGTH: Give the starting length of the segment.
!B
!B 	END LENGTH: Give the ending length of the segment.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: contour length segment ")

DIM Answer$[256]
DIM Destination$[256]
DIM Contour$[256]
DIM Slength$[256]
DIM Elength$[256]
DIM Name$[256]

Var_object=CheckVarObject
IF ExitScript(Destination$) THEN Leave

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

Stat=SetInputFormat("n4","")
Slength=GetValue("STARTING LENGTH")
IF (ExitScript(Destination$)) THEN Leave
No_slen_var= LastVariableInput(Slength$)

Stat=SetInputFormat("n4","")
Elength=GetValue("ENDING LENGTH")
IF (ExitScript(Destination$)) THEN Leave
No_elen_var= LastVariableInput(Elength$)


Stat=GenerateVarName(WsGroupEnt,Name$)
RecordFunctionOn
Stat=RecordDescr("CONTOUR: Contour length segment")
IF No_slen_var THEN
	V1= FreeParameter("Starting length",Slength)
ELSE
	V1= FreeParameter("Starting length",Slength$)
END IF
IF No_elen_var THEN
	V2= FreeParameter("Ending length",Elength)
ELSE
	V2= FreeParameter("Ending length",Elength$)
END IF
C1=ContLengthSegment(Contour$,V1,V2)
Stat=AutoNameGroup(C1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("contour len segment")
Stat= AddGroupToUndo(WsUBCreateMode,C1,1,WsTrue)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

Stat= PlotEntity(Contour$)
Stat= PlotEntity(C1)
GOTO Pick_contour

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

