
! script name: dynvlines.d/dynamictwopts
! var_topic: construct line through two points

!A
!A NAME:
!A
!A 	Dynamic Line: Two 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 	PICK LINE ENDPOINT: Pick the endpoint of the line.
!B 		NOTE: To enter the coordinates, instead of picking the
!B 		endpoint of the line, see DYNAMIC INPUT OPTIONS.
!B
!C NOTES:
!C
!C 	The dynamic input mode is an option that may be turned off by
!C 	setting the variable "Graphical mode=0".  To set the variable,
!C 	under "Settings", select "Variables".  The selection box will appear
!C 	at this time.  Select "Graphical mode=1" and change the
!C 	setting to "0".  The dynamic input mode is the default whenever
!C 	Synergy is started.  This change is for this session of Synergy
!C 	only.
!C
!C 	The dynamic input mode may be turned off for future sessions of
!C 	Synergy by going to "Settings" and selecting "Constants".  The editor
!C 	will bring up the setconstants script.  The following line needs
!C 	to be modified (the 1.0 needs to be changed to 0.0):
!C
!C 		V10=CreateVariable("Graphical mode",WsSystemVars,1.0)
!C
!C 	to:
!C
!C 		V10=CreateVariable("Graphical mode",WsSystemVars,0.0)
!C
!C 	The line is near the middle of the script.
!C
!# see also - points.d/dyninput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: dynamic line two points ")

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

Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)

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

Start:!
Stat=SetPickMask(WsPickNoSurf)
ActivateUndo
Units= CurrentUnits
IF Units= WsMetric THEN
        Length1= 25
ELSE
        Length1= 1
END IF

stat= SetInputFormat("n4b","")
Stat= PointInputMode(1)
Line_loop:Ps=XyzInput("STARTING",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Ps) THEN Line_loop
E1= LastPickEnt
Para1= LastPickPara
Pick_return1= CurrPickReturn
IF NOT ValidDependency(E1) THEN 
	E1= CopyEntity(Ps)
	Stat= EntityNameCheck(E1,Point1$)
	Ps_created=WsTrue
ELSE
	Stat= EntityNameCheck(E1,Point1$)
	Ps_created=WsFalse
END IF
Stat=SetLastPoint(Ps)

IF NOT Graphical_mode THEN
End_point:!
	Stat= PointInputMode(1)
	Pe=XyzInput("ENDING",WsXyzInput)
	IF (ExitScript(Destination$)) THEN Leave
	IF NOT ValidGeometry(Pe) THEN Line_loop
	E2= LastPickEnt
	Para2= LastPickPara
	Pick_return2= CurrPickReturn
	IF NOT ValidDependency(E2) THEN
       		 E2= CopyEntity(Pe)
       		 Stat= EntityNameCheck(E2,Point2$)
		 Pe_created=WsTrue
	ELSE
       		 Stat= EntityNameCheck(E2,Point2$)
		 Pe_created=WsFalse
	END IF
	Stat=SetLastPoint(Pe)
ELSE
Graphical: PlotOff
	Pe= PtIncrXyz(Ps,Length1,0.0,0.0)
	L1= LineTwoPoints(Ps,Pe)
	Stat= MakeInvisible(L1)
	Stat= MakeInvisible(Pe)
	PlotOn

	Vnum= LastPickView
	stat= SetInputFormat("n4b","")
	Stat= PointInputMode(1)
	Stat=DynamicEntity(Vnum,L1,Ps,Pe,WsDynamicEnd,"PICK LINE ENDPOINT")
	IF (ExitScript(Destination$)) THEN
        	Stat=DeleteEntity(L1,WsTrue)
        	GOTO Leave
	END IF
	E2= LastPickEnt
	Para2= LastPickPara
	Pick_return2= CurrPickReturn
	IF NOT ValidDependency(E2) THEN
       		 E2= CopyEntity(Pe)
       		 Stat= EntityNameCheck(E2,Point2$)
		 Stat= MakeVisible(E2)
		 Pe_created=WsTrue
	ELSE
       		 Stat= EntityNameCheck(E2,Point2$)
		 Pe_created=WsFalse
	END IF
END IF

PlotOff
Stat=SetLastPoint(Pe)
Stat=DeleteEntity(Ps,WsTrue)
Stat=DeleteEntity(Pe,WsTrue)
Stat=DeleteEntity(L1,WsTrue)
PlotOn

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)
CASE WsNearest
        Ps= ParameterReturnPt(Point1$,Para1,WsNearest)
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)
CASE WsNearest
        Pe= ParameterReturnPt(Point2$,Para2,WsNearest)
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("var line")
IF Ps_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point1$)
IF Pe_created THEN Stat= AddItemToUndo(WsUBCreateMode,Point2$)
Stat= AddItemToUndo(WsUBCreateMode,L1)
Stat= AddItemToUndo(WsUBCreateMode,Curr_record)

GOTO Line_loop

Leave:!
Stat=SetPickMask(WsPickGeometry)
Stat= PointInputMode(0)
Stat= DeleteEntityList(Ps,Pe)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 IF Destination$= "SCRIPTSTART" THEN Start
         IF Destination$= "BACKUP" THEN Start
	 LOAD Destination$
END IF
END
