Jump to content

Recommended Posts

Posted

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!

Posted

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.

Posted
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.

image.thumb.png.acf73b0a7f88d8aa70f00e91e346b1c2.png

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. 

Posted (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).

 

 

image.thumb.png.85fd1a40d2edcc81dce998aefcd30ba9.png

 

Note: you need to select group by group to get only line or polyline with the highest length.

 

Best regards.

 

Edited by Saxlle
Posted
1 hour ago, Saxlle said:

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).

 

 

image.thumb.png.85fd1a40d2edcc81dce998aefcd30ba9.png

 

Note: you need to select group by group to get only line or polyline with the highest length.

 

Best regards.

 

 

Thanks for the answer ! I tested DOL and it unfortunately doesn’t solve my case.

That routine keeps the single longest object from the entire selection, but it doesn’t check whether objects are collinear and overlapping. In my drawings I often have a LINE and a PLINE that lie on the same line with partial overlap; draw order puts the shorter one on top, so OVERKILL keeps the short piece. What I need is:

Work with LINE and LWPOLYLINE (straight segments).

Group only collinear segments whose projections overlap (within a small tolerance).

In each group, keep the longest and delete the shorter overlapping pieces.

Do not touch segments that are merely end-to-end (no overlap).

Ignore draw order.

If anyone has a LISP that does this “overlap-aware, keep-longest” behavior, I’d really appreciate it

Posted
19 hours 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.

Ekrangrnts2025-08-14142602.png.4824bfe5e0dbb0d2659f9aa33e96be9c.png

 

@SLW210 you are right. 

When I run the OVERKILL dialog with the options shown in the screenshot (tolerance 0.000001, all “Ignore object property” boxes checked, Optimize segments within polylines, Ignore polyline segment widths, Do not break polylines, Combine co-linear objects that partially overlap, Combine co-linear objects when aligned end to end, Maintain associative objects), I get exactly the result I want.

I’d like to run this silently from LISP—no dialog—so that the same settings are always used.
Calling it like this:

(command "_.-OVERKILL" ss "" "")

seems to use whatever options were last chosen in the dialog, not the fixed set I want.

I tried to “force” the settings by editing the registry here:

HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R24.3\ACAD-0001:409\Profiles\<<Unnamed Profile>>\Dialogs\Overkill

but AutoCAD didn’t pick up the changes (no effect on command behavior).

Questions:

Is there a documented way to pass all of these options via the command-line version of OVERKILL in a single LISP call (i.e., set tolerance, ignore list, and all Yes/No toggles explicitly), so it doesn’t rely on the last-used dialog state?

If not, is there another supported method (sysvars, .NET/ObjectARX API, etc.) to set OVERKILL options programmatically?

Why don’t edits under the …\Dialogs\Overkill registry key take effect—am I writing to the wrong location, or are these values cached elsewhere/per-drawing?

AutoCAD version: R24.3 (profile ACAD-0001:409).
Goal: run OVERKILL on selected LINE and PLINE objects with the exact dialog settings above, without showing the dialog and without depending on last-used options.

Thanks!

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...