
! script name: lines.d/tangentline
! topic: construct line tangent to an element

!A
!A NAME:
!A
!A 	Tangent Line
!A
!A DESCRIPTION:
!A
!A 	This script constructs a line tangent to an element, at a point
!A 	on the element.  If the point selected is not on the element, the
!A 	closest point on the element is used.
!A
!A~ image location - images/tangentline.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK TANGENT ELEMENT: Pick the entity that will be tangent
!B 		to the line constructed.
!B
!B 	INPUT ABS X,Y,Z: Enter the X,Y,Z coordinates of the point,
!B 		through which the tangent line will be constructed.  If the
!B 		point is not on the entity, then the closest point on the
!B 		entity will be used for the tangent line construction.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!# see also - points.d/xyzinput.hlp

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

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

DEG

ActivateUndo
Line_length=NamedVarVal("3D Normal Length",Ws3DSystemVars,1.0)

Line_loop:!
Stat=DynLabel("Length:"&VAL$(Line_length))
stat= SetInputFormat("n4","")
E1=PickEntity("PICK TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave

Pt=XyzInput("TANGENT LOCATION INPUT",WsXyzInput)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Pt) THEN Line_loop

Line_length= DynBufferValue(0,Line_length)
IF Line_length=0 THEN
   L1=TangentLine(E1,Pt,WsUnTrimmed,GetDefault(WsLineLength))
ELSE
   L1=TangentLine(E1,Pt,WsTrimFirst,Line_length)
END IF

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

Leave:!
Stat= DynLabel("")
Stat=DeleteEntity(Pt)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
