
! script name: lines.d/linepointtan
! topic: construct line through point tangent to entity

!A
!A NAME:
!A
!A 	Point: Tangent
!A
!A DESCRIPTION:
!A
!A 	This script constructs a line through a point tangent to an entity.
!A
!A~ image location - images/linepttan.gif
!A
!B INSTRUCTIONS:
!B
!B 	INPUT ABS X,Y: Enter the X,Y coordinates of the point, through
!B 		which the line tangent to the entity will be constructed.
!B 		NOTE: See XYZ INPUT OPTIONS.
!B
!B 	PICK TANGENT ELEMENT: Pick the entity that will be tangent to
!B 		the line constructed.
!B
!# see also - points.d/xyzinput.hlp

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

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

DEG
Graphical_mode=NamedVarVal("Graphical mode",WsSystemVars,1.0)
IF Graphical_mode THEN LOAD "lines.d/dynlinepttan"

ActivateUndo
Ploop:!
stat= SetInputFormat("n4","")
P1=XyzInput("INPUT",WsXyOnly)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(P1) THEN Ploop

E2=PickEntity("PICK TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
P2=LastPickPoint

C1=SelectTwoTan(P1,P1,E2,P2,WsTRIMMED)

Stat=DeleteEntity(P1)
Stat=DeleteEntity(P2)
ActivateUndo
Stat= AdvanceUndoNumber("line")
Stat= AddItemToUndo(WsUBCreateMode,C1)
GOTO Ploop

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