
! script name: vlines.d/linechain
! var_topic: links a series of points by line segments

!A
!A NAME:
!A
!A 	Line Chain	VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script links together a series of points by line segments.
!A 	The first line is defined by two points.  The next line and all
!A 	subsequent lines are connected to the end point of the last line
!A 	defined in this script.
!A
!A~ image location - images/linechain.jpg
!B INSTRUCTIONS:
!B
!B 	STARTING ABS X,Y,Z: Enter the X,Y,Z coordinates of the
!B 		start point for the line.  The coordinates for the
!B 		starting point are only asked when the script is entered.
!B 		The next line assumes the start point of the line is
!B 		the end point of the last line described in this script.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	ENDING ABS X,Y,Z: Enter the X,Y,Z coordinates of the
!B 		end point of the line.  This point becomes the start
!B 		point of the next line as long as this script is not exited.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: line chain ")

DIM Answer$[256]
DIM Point1$[256]
DIM Point2$[256]
DIM Name$[256]
DIM Destination$[256]
DEG

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

ActivateUndo
Start_point:stat= SetInputFormat("n4","")
Element1=PickEntity("STARTING POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Element1) THEN Start_point
Stat= EntityNameCheck(Element1,Point1$)
Para1= LastPickPara
Pick_return1= CurrPickReturn


Line_loop:!
Ps= ParameterReturnPt(Point1$,Para1,Pick_return1)
Stat=SetLastPoint(Ps)
Element2=PickEntity("ENDING POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(Element2) THEN Line_loop
Stat= EntityNameCheck(Element2,Point2$)
Para2= LastPickPara
Pick_return2= CurrPickReturn
Pe= ParameterReturnPt(Element2,Para2,Pick_return2)
Stat=SetLastPoint(Pe)

Stat= DeleteEntity(Ps)
Stat= DeleteEntity(Pe)

Stat= GenerateVarName(WsLineEnt,Name$)

RecordFunctionOn
Stat= RecordDescr("LINE: Two points")
Stat= SetRecDelLastExec
SELECT Pick_return1
CASE WsGeometryEnd
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryEnd)
CASE WsGeometryMid
        Ps= ParameterReturnPt(Point1$,Para1,WsGeometryMid)
CASE WsGeomCenter
        Ps= ParameterReturnPt(Point1$,Para1,WsGeomCenter)
END SELECT
SELECT Pick_return2
CASE WsGeometryEnd
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryEnd)
CASE WsGeometryMid
        Pe= ParameterReturnPt(Point2$,Para2,WsGeometryMid)
CASE WsGeomCenter
        Pe= ParameterReturnPt(Point2$,Para2,WsGeomCenter)
END SELECT
L1=LineTwoPoints(Ps,Pe)
Stat= NameEntity(L1,Name$)
Stat= DeleteEntityList(Ps,Pe)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Point1$)
Stat= PlotEntity(Point2$)
Stat= PlotEntity(L1)

ActivateUndo
Stat= AdvanceUndoNumber("line")
Stat= AddItemToUndo(WsUBCreateMode,L1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

Point1$= Point2$
Para1=Para2
Pick_return1= Pick_return2
Element1= Element2
GOTO Line_loop

Leave:!

Stat=DeleteEntityList(Ps,Pe)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
