
! 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_loop:!
stat= SetInputFormat("n4","")
E1=PickEntity("PICK TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave

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

L1=TangentLine(E1,Pt,WsTRIMMED)

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

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