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

!A
!A NAME:
!A
!A 	Line Chain
!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 start
!B 		point for the line.  The coordinates for the starting point
!B 		are only asked when the script is entered.  The next line
!B 		assumes the start point of the line is the end point of the
!B 		last line described in this script.
!B
!B 	ENDING ABS X,Y,Z: Enter the X,Y,Z coordinates of the end point of the
!B 		line.  This point becomes the start point of the next line as
!B 		long as this script is not exited.
!B
!# see also - points.d/xyzinput.hlp

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

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

Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)
IF Graphical_mode THEN LOAD "lines.d/dynamicchain"

ActivateUndo
Stat=SetInputFormat("n4a1=",",I,A,")

Ps=XyzInput("STARTING",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
Stat=SetLastPoint(Ps)

Line_loop:!
Pe=XyzInput("ENDING",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave

L1=LineTwoPoints(Ps,Pe,WsTRIMMED)

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

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

Leave:!

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