nickg2027 Posted July 7, 2009 Posted July 7, 2009 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. Quote
ReMark Posted July 7, 2009 Posted July 7, 2009 Maybe this will get you started. It's a link to Bill Kramer's LISP routine CDNC5-02.lsp that finds all intersections between objects in the selection set. It may have to be modified to fit your circumstances. Page down to post #16. http://forums.cadalyst.com/showthread.php?t=5617&page=2 Quote
nickg2027 Posted July 7, 2009 Author Posted July 7, 2009 how would i enter that into autocad. Sorry for being new but any help would be greatly apreciated. Quote
ReMark Posted July 7, 2009 Posted July 7, 2009 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. Quote
nickg2027 Posted July 9, 2009 Author Posted July 9, 2009 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?? Quote
ReMark Posted July 9, 2009 Posted July 9, 2009 Let me give this thread a "bump". Maybe Lee Mac may have a clue. Here goes...bump Quote
Lee Mac Posted July 10, 2009 Posted July 10, 2009 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 Quote
Lee Mac Posted July 10, 2009 Posted July 10, 2009 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 Quote
ReMark Posted July 10, 2009 Posted July 10, 2009 Thank you Lee for your assistance. I really do appreciate it. Quote
Lee Mac Posted July 11, 2009 Posted July 11, 2009 Thank you Lee for your assistance. I really do appreciate it. No problem, I enjoy doing LISPs working with intersections, they are quite useful Quote
Israel Posted March 30, 2021 Posted March 30, 2021 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 Quote
Lee Mac Posted March 31, 2021 Posted March 31, 2021 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) Quote
CyberAngel Posted March 31, 2021 Posted March 31, 2021 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. Quote
nshafarzek Posted October 20, 2021 Posted October 20, 2021 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! Quote
Engineer_Yasser Posted October 31, 2023 Posted October 31, 2023 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 Quote
Lee Mac Posted October 31, 2023 Posted October 31, 2023 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. Quote
Engineer_Yasser Posted November 1, 2023 Posted November 1, 2023 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 Test 2.dwg Quote
Lee Mac Posted November 1, 2023 Posted November 1, 2023 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). 1 Quote
Engineer_Yasser Posted November 1, 2023 Posted November 1, 2023 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 Quote
BIGAL Posted November 1, 2023 Posted November 1, 2023 (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 November 1, 2023 by BIGAL 1 Quote
Recommended Posts
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.