p7q Posted 2 hours ago Posted 2 hours ago Hi everyono, I’ve tried using the OVERKILL command in AutoCAD to remove overlapping objects. However, it doesn’t have a parameter to keep only the longest object when there are overlaps. I’m looking for an AutoLISP routine that can work with LINE and PLINE (polylines), detect overlapping or collinear segments, and delete all but the longest one in each group. Thanks in advance! Quote
SLW210 Posted 2 hours ago Posted 2 hours ago There is an option in OVERKILL to combine co-linear objects that partially overlap. If that's not what you need, post a before/after .dwg. Quote
p7q Posted 1 hour ago Author Posted 1 hour ago 21 minutes ago, SLW210 said: There is an option in OVERKILL to combine co-linear objects that partially overlap. If that's not what you need, post a before/after .dwg. The issue is that in my case the longest object is underneath and the shorter one is on top in the draw order. When I run OVERKILL, it keeps the top-most object, which ends up deleting my longest segment. What I need is to always keep the longest overlapping segment (LINE or PLINE) and delete the shorter one, regardless of the draw order. Quote
Saxlle Posted 21 minutes ago Posted 21 minutes ago (edited) Hi @p7q, If this what you want, you can try with this: (prompt "\nTo run a LISP type: DOL (DeleteOverlappingLines)") (princ) (defun c:DOL ( / ss len i ename_length_list ename ename_length) (setq ss (ssget (list (cons 0 "*LINE"))) len (sslength ss) i 0 ename_length_list (list) ) (while (< i len) (setq ename (ssname ss i) ename_length (getpropertyvalue ename "Length") ename_length_list (append ename_length_list (list (list ename ename_length))) i (1+ i) ) ) (setq ename_length_list (vl-sort ename_length_list (function (lambda (x1 x2) (< (cadr x1) (cadr x2))))) ename_length_list (vl-remove (last ename_length_list) ename_length_list) total_len (itoa (length ename_length_list)) ) (foreach x ename_length_list (entdel (car x)) ) (prompt (strcat "\nThe total number of deleted lines is " total_len "!")) (princ) ) and you will get something like this (picture 1). Note: you need to select group by group to get only line or polyline with the highest length. Best regards. Edited 14 minutes ago by Saxlle 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.