
! script name: vlines.d/twoxyzpoints
! var_topic: construct line through two xyz points

!A
!A NAME:
!A
!A 	Two XY(Z) Points --- VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a line through two points. The coordinates
!A 	of the points are input in this script.
!A
!B INSTRUCTIONS:
!B
!B 	STARTING ABS X,Y,Z: Enter the X,Y,Z coordinates of the
!B 		start point of the line.  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.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: two xy(z) points ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name1$[256]
DIM Name2$[256]
DIM Name3$[256]
DEG

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


stat= SetInputFormat("n4","")
Line_loop:Ps=XyzInput("STARTING",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Line_loop

Stat=SetLastPoint(Ps)
Pe=XyzInput("ENDING",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pe) THEN Line_loop


CALL GetXyzValues(Ps,X1,Y1,Z1)
CALL GetXyzValues(Pe,X2,Y2,Z2)
Stat=DeleteEntity(Ps)
Stat=DeleteEntity(Pe)

Stat= GenerateVarName(WsPointEnt,Name1$)
RecordFunctionOn
Stat= RecordDescr("POINT: XYZ")
Stat= SetRecDelLastExec
V1= FreeParameter("Xs",X1)
V2= FreeParameter("Ys",Y1)
V3= FreeParameter("Zs",Z1)
Ps= PointXyz(V1,V2,V3)
Stat= NameEntity(Ps,Name1$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("point xyz")
Stat= AddItemToUndo(WsUBCreateMode,Ps)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

Stat= GenerateVarName(WsPointEnt,Name2$)
RecordFunctionOn
Stat= RecordDescr("POINT: XYZ")
V1= FreeParameter("Xe",X2)
V2= FreeParameter("Ye",Y2)
V3= FreeParameter("Ze",Z2)
Pe= PointXyz(V1,V2,V3)
Stat= NameEntity(Pe,Name2$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

ActivateUndo
Stat= AdvanceUndoNumber("point xyz")
Stat= AddItemToUndo(WsUBCreateMode,Pe)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)


Stat= GenerateVarName(WsLineEnt,Name3$)
RecordFunctionOn
Stat= RecordDescr("LINE: Two points")
L1=LineTwoPoints(Name1$,Name2$,WsTRIMMED)
Stat= NameEntity(L1,Name3$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Name1$)
Stat= PlotEntity(Name2$)
Stat= PlotEntity(L1)
Stat=SetLastPoint(Pe)

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

Leave:!

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

SUB GetXyzValues(ENTITY Pt,REAL X,Y,Z)
X= XPointValue(Pt)
Y= YPointValue(Pt)
Z= ZPointValue(Pt)
SUBEND

