Looking for a LISP to check if a line and an arc or two arcs are Tangent

Looking for a LISP to check if a line and an arc or two arcs are Tangent

lunarfaze
Enthusiast Enthusiast
1,331 Views
5 Replies
Message 1 of 6

Looking for a LISP to check if a line and an arc or two arcs are Tangent

lunarfaze
Enthusiast
Enthusiast

We are looking for a LISP to check if a line meeting an arc/curve or an arc/curve meeting a reverse arc/curve are tangent.  Searching through the archives here, I found something similar posted by BILLZ from 2005.  It works perfect for Line to Arc but does not do Arc to Arc.  I am posting his LISP below for reference and maybe someone can simply modify it.  We are running 2008 Land Desktop Companion so we do no use Smart Draft.  

 

Also, can the Pop Up Alert be changed to just show in the command prompt area?

 

As always, thank you guys so much.

 

Here's Billz's Code from 2005:

========================

(defun c:checktangent ();(/ Ar ArcEnt Ln LnEnt)
(vl-load-com)
;---;
(prompt "\nLine.")
(setq LnEnt (ssget "+.:E:S" '((0 . "LINE,POLYLINE,LWPOLYLINE")))
)
(prompt "\nArc or Circle.")
(setq ArEnt (ssget "+.:E:S" '((0 . "ARC,CIRCLE")))
)
;---;
(cond ((and LnEnt ArEnt)
(setq Ln (vlax-ename->vla-object (ssname LnEnt 0))
Ar (vlax-ename->vla-object (ssname ArEnt 0))
)
(if (and (vla-intersectwith Ln Ar acExtendBoth)
(= (length (vlax-safearray->list (variant-value (vla-intersectwith ln ar acExtendBoth)))) 3)
)
(alert "Line is tangent.")
(alert "Line is NOT tangent.")
)
)
(t (prompt "\nInvalid entities."))
)
(princ)
)

0 Likes
1,332 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

What it's doing is checking whether, if both objects are extended, they intersect only once -- the 3 is the raw quantity of XYZ coordinates in the conglomerated intersection(s) -- it would be 6 if they intersect twice, meaning they're not tangent.  The same should work for two Arcs/Circles in the same way.  Try these modifications:

 

....

;---;

(prompt "\nArc or Circle."); in place of the Line-related one
(setq ArEnt1 (ssget "+.:E:S" '((0 . "ARC,CIRCLE")))
)

(prompt "\nArc or Circle.")
(setq ArEnt2 (ssget "+.:E:S" '((0 . "ARC,CIRCLE")))
)
;---;
(cond ((and ArEnt1 ArEnt2)
(setq Ar1 (vlax-ename->vla-object (ssname LnEnt 0))
Ar2 (vlax-ename->vla-object (ssname ArEnt 0))
)
(if (and (vla-intersectwith Ar1 Ar2 acExtendBoth)
(= (length (vlax-safearray->list (variant-value (vla-intersectwith Ar1 Ar2 acExtendBoth)))) 3)
)
(prompt "Arcs/Circles are tangent.")
(prompt "Arcs/Circles are NOT tangent.")

....

 

By the way, I can see the original sometimes giving false non-tangency reports if a Polyline is selected for the "Line" object, because Polylines can bend around, and even if it is tangent where it meets the curve object, its extension(s) could intersect that elsewhere, which would cause it to report their NOT being tangent.  That can likely be overcome, but maybe not in a foolproof way, and I'm not sure how complicated it would be.

 

The above modifications are limited to use with only two Arcs/Circles.  If you want the same routine to allow for either a Line and a curve or two curves [omitting the above complications of a Polyline for the moment], do this for one of the selections [two Lines would be a meaningless situation]:

(prompt "\nLine or Arc or Circle.")
(setq ArEnt1 (ssget "+.:E:S" '((0 . "LINE,ARC,CIRCLE")))
)

 

and presumably change the variable name and those affected by it later.  If you want the option to choose either the Line or the curve first, that can probably be accommodated, but would be more complicated.

 

Also, the same could be expanded to cover Ellipses and/or Splines for the curved object(s) [though Splines present the same complications as Polylines], and Rays or Xlines for the straight one.

Kent Cooper, AIA
Message 3 of 6

lunarfaze
Enthusiast
Enthusiast

Kent, thank you so much for your reply and edits!  I appreciate it so much.  Also, I love how you explain how it works.  That's cool and helped me understand it.

 

I am testing the changes out now and will post later.

0 Likes
Message 4 of 6

lunarfaze
Enthusiast
Enthusiast

Hello Kent,

 

Thank you again for this.  I really appreciate it.  

 

First, getting rid of the Popup worked perfect.  I tried it before (what I thought was the same) and it didn't work.  I must have had a typo.

 

Second, the checking two arcs does not seem to work.  The only solution it returns is NOT Tangent, regardless of tangency.  I've tried it multiple times are arcs that I know are perfectly tangent and not polylines.  Any ideas?

0 Likes
Message 5 of 6

Kent1Cooper
Consultant
Consultant

@lunarfaze wrote:

.... the checking two arcs does not seem to work.  The only solution it returns is NOT Tangent, regardless of tangency.  I've tried it multiple times are arcs that I know are perfectly tangent and not polylines.  Any ideas?


Whoops -- I missed a couple of variable name adjustments:

....

(cond ((and ArEnt1 ArEnt2)
(setq Ar1 (vlax-ename->vla-object (ssname ArEnt1 0))
Ar2 (vlax-ename->vla-object (ssname ArEnt2 0))
)

....

Kent Cooper, AIA
0 Likes
Message 6 of 6

Lineabove
Collaborator
Collaborator

Hi.

 

Please post your revised lisp.

I am interested...

 

 

Thanks

0 Likes