
! script name: vlines.d/xyzptangle
! var_topic: construct line through xyz point at angle

!A
!A NAME:
!A
!A 	XYZ Point Angle   VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script will construct a line through a point, at a
!A 	specified angle.
!A
!B INSTRUCTIONS:
!B
!B 	INPUT ABS X,Y,Z: Enter the X,Y,Z coordinates of the
!B 		point, through which the line will be constructed
!B 		at the specified angle.  NOTE: See XYZ INPUT OPTIONS.
!B
!B 	ANGLE: Enter the angle of the line that will be
!B 		constructed through the defined point.
!B
!# see also - points.d/xyzinput.hlp

stat=ChangeLabelStr("ScriptNameStatus","Function: point angle ")

DIM Answer$[256]
DIM Destination$[256]
DIM Name1$[256]
DIM Name2$[256]
DIM Angle_var$[256]

DEG

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


ActivateUndo
Line_loop:Stat=SetInputFormat("n4","")
Pc=XyzInput("INPUT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pc) THEN Line_loop

Angle_ques:Angle=InputAngle("ANGLE")
IF (ExitScript(Destination$)) THEN Leave
No_angle_var= LastVariableInput(Angle_var$)
L1= LastPickEnt
IF ValidGeometry(L1) THEN
	IF NOT ValidDependency(L1) THEN Angle_ques
        Stat= EntityNameCheck(L1,Angle_var$)
        No_angle_var=0
END IF

CALL GetXYZValues(Pc,X1,Y1,Z1)
Stat=DeleteEntity(Pc)

Stat= GenerateVarName(WsPointEnt,Name1$)
RecordFunctionOn
Stat= RecordDescr("POINT: XYZ")
Stat= SetRecDelLastExec
V1= FreeParameter("X",X1)
V2= FreeParameter("Y",Y1)
V3= FreeParameter("Z",Z1)
Pc= PointXYZ(V1,V2,V3)
Stat= NameEntity(Pc,Name1$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

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

Stat= GenerateVarName(WsLineEnt,Name2$)
RecordFunctionOn
Stat= RecordDescr("LINE: point angle")
IF No_angle_var THEN
	V1= FreeParameter("Angle",Angle)
	L1=PointAngle(Name1$,V1)
ELSE
	L1=PointAngle(Name1$,Angle_var$)
END IF
Stat= NameEntity(L1,Name2$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Name1$)
Stat= PlotEntity(L1)
Stat=SetEqualsValue(Angle)

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

