
! script name: vtrimming.d/ltwotantrim
! var_topic: construct line tangent to two entities

!A
!A NAME:
!A
!A 	Tangent Line Trim		VARIATIONAL
!A
!A DESCRIPTION:
!A
!A 	This script constructs a line tangent to two entities.
!A
!A~ image location - images/tangentlinetrim.jpg
!B INSTRUCTIONS:
!B
!B 	PICK FIRST TANGENT ELEMENT: Pick
!B 		one of the two entities that will be
!B 		tangent to the line constructed.
!B
!B 	PICK NEXT TANGENT ELEMENT: Pick 
!b 		the other entity that will be tangent
!B 		to the line constructed.
!B

Stat=ChangeLabelStr("ScriptNameStatus","Function: two tangents trim")

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
Para1=LastPickPara
Stat=EntityNameCheck(E1,Name1$)

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

ActivateUndo
Stat= AdvanceUndoNumber("tangent line trim")
Stat= AddItemToUndo(WsUBModifyMode,Name1$)
Stat= AddItemToUndo(WsUBModifyMode,Name2$)

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

Stat= PlotEntity(L1)
Stat= PlotEntity(Name1$)
Stat= PlotEntity(Name2$)
IF NOT ValidGeometry(L1) THEN
	DelLastVarRecord
ELSE
	Stat= AddItemToUndo(WsUBCreateMode,L1)
	Stat= AddItemToUndo(WsUBCreateMode,Curr_record)
END IF
GOTO Ploop

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

