Intersection with Xref (Lisp)

Intersection with Xref (Lisp)

rodeghieromaxime
Participant Participant
1,565 Views
6 Replies
Message 1 of 7

Intersection with Xref (Lisp)

rodeghieromaxime
Participant
Participant

Hi everyone , 

I try to find a way to get coordinates of intersections point between a line and a Xref 

to get distance between multiple point in Xref but I don't know how can I do that ... 

Can someone Help me ?? 

 

Thanks for advance 

 

Max

0 Likes
Accepted solutions (1)
1,566 Views
6 Replies
Replies (6)
Message 2 of 7

S.Faris
Advisor
Advisor

Start a Polyline , click on every point where you need the Coordinate and once you finish doing it. Select the Polyline and use command LIST to get the coordinates.

SALMANUL FARIS

0 Likes
Message 3 of 7

rodeghieromaxime
Participant
Participant

Hi S. Faris , 

Thanks for your answer , 

 

I've Already thought about this solution , with 2 or 3 lines no problem but with more than 10 lines it becomes complicated ... I try to find a way to trace one line and get all the intersections with an XREF . 

 

Max

0 Likes
Message 4 of 7

S.Faris
Advisor
Advisor

Can you be more specific about "I try to find a way to trace one line and get all the intersections with an XREF". Post a screenshot or a dwg  if possible

SALMANUL FARIS

0 Likes
Message 5 of 7

john.uhden
Mentor
Mentor

Let's say that obj1 is the vla-object representing the xref and that obj2 is the vla-object representing a polyline that intersects with the xref one or more times.

The intersections can be obtained using:

(setq ints (vlax-invoke obj1 'intersectwith obj2 0))

Of course the result is what we call a flat list, not a list of separate points, but a list like

(x1 y1 z1 x2 y2 z2 ... xn yn zn)

I use the following function to convert the flat list into a list of 3D points:

    ;; Function to group a list of items into a list of
    ;; multiple lists, each of length N, e.g.
    ;; '(A B C D E F G H I) -> '((A B C)(D E F)(G H I))
    (defun @group (lst n / item new)
      (foreach element (reverse lst)
        (setq item (cons element item))
        (if (= (length item) n)
          (setq new (cons item new) item nil)
        )
      )
      new
    )

The programmer must know in advance whether the flat list is 2D or 3D.

If the flat list is 3D then (setq ints (@group ints 3))

If the flat list is 2D then (setq ints (@group ints 2))

 

You may be surprised with the results because the intersectwith method treats things like inserts and mtext as though they were a rectangular box, just the same as the getboundingbox method.  So there are likely to be fewer intersections returned than what you deduce visually.  I have not yet found a way using Lisp to retrieve all the apparent intersections.  I suppose it might be done by temporarily exploding the insert or mtext and trying to interpret the intersection points of each component, but I have successfully avoided such an undertaking for lack of need.  It's too bad that Autodesk doesn't provide us a getboundingpolygon method.

John F. Uhden

Message 6 of 7

rodeghieromaxime
Participant
Participant

Hi  

 

 

 

 

 

0 Likes
Message 7 of 7

rodeghieromaxime
Participant
Participant
Accepted solution

Hi Everyone , 

 

After many research , I finally found the solution ( thanks to Patrick_35 for his routine to Copy elements from Xref ( find on this Forum : https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/copy-objects-from-xref/td-p/2552308

With adding some code , here is video of the result ( which is perfect for me 🙂 ) :

0 Likes