
! script name: vlines.d/tangentline
! var_topic: construct line tangent to an element

!A
!A NAME:
!A
!A 	Tangent Line	VARIATIONAL
!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 to the
!B 		line constructed.
!B
!B 	INPUT ABS X,Y,Z: Enter the X,Y,Z coordinates of the point, through
!B 		which the tangent line will be constructed.  If the point is
!B 		not on the entity, then the closest point on the entity will
!B 		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]
DIM Name$[256]
DIM Point$[256]
DIM Element$[256]

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

DEG

ActivateUndo
Line_loop:!
stat= SetInputFormat("n4","")
E1=PickEntity("PICK TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Line_loop
Stat= EntityNameCheck(E1,Element$)

Pick_point:!
E1=PickEntity("POINT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Line_loop
Stat= EntityNameCheck(E1,Point$)
T= LastPickPara
Pick_return= CurrPickReturn

Stat= GenerateVarName(WsLineEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("LINE: tangent line at a point")
Stat= SetRecDelLastExec
SELECT Pick_return
CASE WsGeometryEnd
        Pc= ParameterReturnPt(Point$,T,WsGeometryEnd)
CASE WsGeometryMid
        Pc= ParameterReturnPt(Point$,T,WsGeometryMid)
CASE WsGeomCenter
        Pc= ParameterReturnPt(Point$,T,WsGeomCenter)
END SELECT
L1=TangentLine(Element$,Pc,WsTRIMMED)
Stat= NameEntity(L1,Name$)
Stat=DeleteEntity(Pc)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Point$)
Stat= PlotEntity(Element$)
Stat= PlotEntity(L1)
IF NOT ValidGeometry(L1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("tangent line")
	Stat= AddItemToUndo(WsUBCreateMode,L1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Line_loop

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