
! script name: vlines.d/linetwotan
! var_topic: construct line tangent to two entities

!A
!A NAME:
!A
!A 	Two Tangents	-- VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a line tangent to two entities.
!A
!A~ image location - images/linetwotan.gif
!A
!B INSTRUCTIONS:
!B
!B 	PICK FIRST TANGENT ELEMENT: Pick one of the two entities that will
!B 		be tangent to the line constructed.
!B
!B 	PICK NEXT TANGENT ELEMENT: Pick the other entity that will be tangent
!B 		to the line constructed.
!B

stat=ChangeLabelStr("ScriptNameStatus","Function: two tangents ")

DIM Destination$[256]
DIM Answer$[256]
DIM Name1$[256]
DIM Name2$[256]
DIM Name$[256]
DIM Radius_var$[256]

DEG

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


ActivateUndo
Ploop:!
Stat= SetInputFormat("n4","")
E1=PickEntity("PICK FIRST TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E1) THEN Ploop
Stat= EntityNameCheck(E1,Name1$)
Para1=LastPickPara

Pick_line2:Stat= SetInputFormat("n4","")
E2=PickEntity("PICK NEXT TANGENT ELEMENT")
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidDependency(E2) THEN Pick_line2
Stat= EntityNameCheck(E2,Name2$)
Para2=LastPickPara


Stat= GenerateVarName(WsLineEnt,Name$)
RecordFunctionOn
Stat= RecordDescr("LINE: Tangent two entities")
Stat= SetRecDelLastExec
P1= ParameterPt(Name1$,Para1)
P2= ParameterPt(Name2$,Para2)
L1=SelectTwoTan(Name1$,P1,Name2$,P2,WsTRIMMED)
Stat= DeleteEntityList(P1,P2)
Stat= NameEntity(L1,Name$)
RecordFunctionOff
Curr_record= CurrentVarRecord
CloseVarRecord

Stat= PlotEntity(Name1$)
Stat= PlotEntity(Name2$)
Stat= PlotEntity(L1)

IF NOT ValidGeometry(L1) THEN
        DelLastVarRecord
ELSE
	ActivateUndo
	Stat= AdvanceUndoNumber("line 2 tangents")
	Stat= AddItemToUndo(WsUBCreateMode,L1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF

GOTO Ploop

Leave:!
Stat= SetInputFormat("n4","")
Stat=SetXyzInput(WsXyzInput)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END



