Jump to content

Recommended Posts

Posted

I have searched high and low for the answer to this. I have found a few programs that people have written for macros to list the coordinates for the intersections of plines. I simply need the total count of intersections. Some of my projects are extremely large and the number of insections can easily reach 100,000. I am drawing a simple 2-d drawing that has transects spaced every 140 ft with intersecting lines every 40 ft. Any help would be greatly appreciated.

Posted

how would i enter that into autocad. Sorry for being new but any help would be greatly apreciated.

Posted

For further information might I suggest that you look at CADTutor's own AutoCAD FAQ section, under the category Customization. There is a "how to" for using an AutoLISP routine that provides all the necessary details.

Posted

Still can't get it to work? The Command Line tells me error: too few arguments. I just want autocad to tell me that in this drawing there is "14" intersections. Any help would be appreciated. I'm at a loss??

autocad.jpg

Posted

Let me give this thread a "bump". Maybe Lee Mac may have a clue. Here goes...bump

Posted
Let me give this thread a "bump". Maybe Lee Mac may have a clue. Here goes...bump

 

I'll see what I can do buddy :D

Posted

This will only count the intersections, as I thought that is what you are after, if you need to see the coords, let me know, as its not too much trouble to get them.

 

Also, this doesn't count self intersections.

 

 

(defun c:pInt (/ ss Objlst i)
 (vl-load-com)
 (if (setq ss (ssget '((0 . "*LINE"))) i 0)
   (progn
     (setq Objlst (mapcar 'vlax-ename->vla-object
                    (vl-remove-if 'listp
                      (mapcar 'cadr (ssnamex ss)))))
     (while (setq Obj (car Objlst))
       (foreach iObj (setq Objlst (cdr Objlst))
         (setq i
           (+
             (length
               (vlax-list->3D-point
                 (vlax-invoke Obj
                   'IntersectWith iObj acExtendNone))) i))))
     (princ (strcat "\n<< " (itoa i) " Intersections, between "
                    (itoa (sslength ss)) " Objects >>")))
   (princ "\n<< Nothing Selected >>"))
 (princ))

(defun vlax-list->3D-point (lst)
 (if lst
   (cons (list (car lst) (cadr lst) (caddr lst))
         (vlax-list->3D-point (cdddr lst)))))

 

Will work on Lines and Polylines, but can be made to work on other objects, I just filtered them for ease of selection.

 

Lee

Posted

Thank you Lee for your assistance. I really do appreciate it.

Posted
Thank you Lee for your assistance. I really do appreciate it.

 

No problem, I enjoy doing LISPs working with intersections, they are quite useful :)

  • 11 years later...
Posted
On 7/10/2009 at 11:39 AM, Lee Mac said:

This will only count the intersections, as I thought that is what you are after, if you need to see the coords, let me know, as its not too much trouble to get them.

 

Also, this doesn't count self intersections.

 

 

 


(defun c:pInt (/ ss Objlst i)
 (vl-load-com)
 (if (setq ss (ssget '((0 . "*LINE"))) i 0)
   (progn
     (setq Objlst (mapcar 'vlax-ename->vla-object
                    (vl-remove-if 'listp
                      (mapcar 'cadr (ssnamex ss)))))
     (while (setq Obj (car Objlst))
       (foreach iObj (setq Objlst (cdr Objlst))
         (setq i
           (+
             (length
               (vlax-list->3D-point
                 (vlax-invoke Obj
                   'IntersectWith iObj acExtendNone))) i))))
     (princ (strcat "\n<< " (itoa i) " Intersections, between "
                    (itoa (sslength ss)) " Objects >>")))
   (princ "\n<< Nothing Selected >>"))
 (princ))

(defun vlax-list->3D-point (lst)
 (if lst
   (cons (list (car lst) (cadr lst) (caddr lst))
         (vlax-list->3D-point (cdddr lst)))))
 

 

 

Will work on Lines and Polylines, but can be made to work on other objects, I just filtered them for ease of selection.

 

Lee

Hi Lee, what is the command prom to execute this program? Im new at this. sorry

 

Posted
12 hours ago, Israel said:

Hi Lee, what is the command prom to execute this program? Im new at this. sorry

 

Wow - that's old code! The command for that program is "PINT", however, here is an updated cleaner version:

(defun c:interscount ( / c i l s x )
    (if (setq s (ssget '((0 . "LINE,LWPOLYLINE"))))
        (if
            (cdr
                (repeat (setq i (sslength s))
                    (setq i (1- i)
                          l (cons (vlax-ename->vla-object (ssname s i)) l)
                    )
                )
            )
            (progn
                (setq c 0)
                (while (setq x (car l))
                    (foreach y (setq l (cdr l))
                        (setq c (+ c (/ (length (vlax-invoke x 'intersectwith y acextendnone)) 3)))
                    )
                )
                (princ (strcat "\n" (itoa c) " intersection" (if (= 1 c) "" "s") " between " (itoa (sslength s)) " objects."))
            )
            (princ "\nPlease select more than one object.")
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

Posted
12 hours ago, Israel said:

Hi Lee, what is the command prom to execute this program? Im new at this. sorry

 

Because it's an AutoLISP program, you must load it first. Use the APPLOAD command, browse to the file that contains the code (it will have a .lsp extension), and make sure it loads properly. At that point you can use the AutoLISP function as if it's an AutoCAD command, type PINT.

 

A word of warning: if you're going to use custom code, it's a good idea to learn a little bit about the language. You don't have to depend on others to debug the code for you, and you have the skills to develop your own code, which makes you more productive and looks good on your resume.

  • 6 months later...
Posted

I'm curious if there's any way to generalize the code above to just select a polyline and look for any intersections with all line segments in the drawing? I'd like to generalize it that way and then print the # of intersections to a textbox at the center of the polyline. I'm relatively new to autolisp so i'm looking for any advice / direction that might be helpful.

 

Thanks!

  • 2 years later...
Posted
On 3/31/2021 at 3:35 PM, Lee Mac said:

 

Wow - that's old code! The command for that program is "PINT", however, here is an updated cleaner version:

(defun c:interscount ( / c i l s x )
    (if (setq s (ssget '((0 . "LINE,LWPOLYLINE"))))
        (if
            (cdr
                (repeat (setq i (sslength s))
                    (setq i (1- i)
                          l (cons (vlax-ename->vla-object (ssname s i)) l)
                    )
                )
            )
            (progn
                (setq c 0)
                (while (setq x (car l))
                    (foreach y (setq l (cdr l))
                        (setq c (+ c (/ (length (vlax-invoke x 'intersectwith y acextendnone)) 3)))
                    )
                )
                (princ (strcat "\n" (itoa c) " intersection" (if (= 1 c) "" "s") " between " (itoa (sslength s)) " objects."))
            )
            (princ "\nPlease select more than one object.")
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

 

Good job Lee

But I got false results sometimes.. can you fix the code, please

Check the attachment dwg file ( check the intersection between 2 polylines ) the answer suppose to be 1 but the result is 3

 

 

Test.dwg

Posted

The ActiveX intersectwith method can be inaccurate when objects are far from the origin (presumably due to the limited precision afforded by the double-precision floating point format); if you move your objects close to the origin, you'll find that the program returns 1 intersection. As such, a possible solution might be to temporarily move the selection set close to the origin prior to calculating the intersection count, before restoring the position of the set.

Posted
11 hours ago, Lee Mac said:

The ActiveX intersectwith method can be inaccurate when objects are far from the origin (presumably due to the limited precision afforded by the double-precision floating point format); if you move your objects close to the origin, you'll find that the program returns 1 intersection. As such, a possible solution might be to temporarily move the selection set close to the origin prior to calculating the intersection count, before restoring the position of the set.

 

 

 

Do you have any idea how to select closed polylines that touch the yellow closed polyline ( not intersected at one point ) as in picture

 

 

1.png

2.png

Test 2.dwg

Posted

Yes - for every yellow segment, you can test whether the segment is collinear with a red segment and if so, whether the extents of both segments is less than the sum of their individual lengths (i.e. testing that they overlap).

  • Like 1
Posted
22 minutes ago, Lee Mac said:

Yes - for every yellow segment, you can test whether the segment is collinear with a red segment and if so, whether the extents of both segments is less than the sum of their individual lengths (i.e. testing that they overlap).

 

Thanks for help 🌷

Posted (edited)

Another is look at using ssget with a small CP function. that is a little box at each vertice, yes it will get duplicates but make a list of entity names and then remove duplicates so only end up with what you want. Will add to my To do. May be able to use ssget "F".

Edited by BIGAL
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...