MARINA Posted Wednesday at 07:56 PM Posted Wednesday at 07:56 PM Hi, I need an AutoLISP routine for AutoCAD that performs an OVERKILL-equivalent cleanup directly inside block definitions, without manually opening each block using BEDIT or REFEDIT. The routine should iterate through the drawing’s BlockTable records / block definitions and process the geometry contained inside each eligible block definition. Technical requirements: Process normal user-created block definitions directly. Do not explode block references. Do not require manually opening or closing each block. Skip Xrefs, layout blocks, anonymous/system blocks, and any block definitions that should not be modified. Process nested block definitions as well, while avoiding infinite loops or repeated unnecessary processing. Remove duplicate and overlapping entities in a way equivalent, or as close as technically possible, to AutoCAD's OVERKILL command. Preserve the original block structure, insertion points, attributes, dynamic block functionality, layers, colors, linetypes, and other entity properties. Avoid modifying block references themselves unless absolutely necessary. Prefer operating directly on the entities stored in each BlockTableRecord rather than entering Block Editor. Ideally, the routine should also: Purge or ignore invalid/erased objects safely. Handle common geometry types such as Lines, Polylines, Arcs, Circles, and similar entities. Use an appropriate geometric tolerance for duplicate detection. Provide a final report showing: Number of block definitions processed. Number of blocks skipped. Number of duplicate/overlapping entities removed, if detectable. Any blocks that failed to process. My main goal is to run one command on a drawing and automatically clean duplicate geometry inside all blocks, including nested blocks, without manually opening each block one by one. Please also advise whether this can be implemented reliably in pure AutoLISP / Visual LISP, or whether a C# AutoCAD .NET plugin would be a better approach, especially if the native OVERKILL command cannot operate directly on BlockTableRecord entities. Quote
BIGAL Posted Thursday at 12:56 AM Posted Thursday at 12:56 AM (edited) Welcome aboard, is there a reason why you do not want to use Bedit ? Would make life a lot easier, a lisp would call bedit and select all objects in the block and could run Overkill then or something like this that I found using Google. Then save the block definition and update the dwg. ; keep longest overlapping lines ; By Saxelle Aug 2025 (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) ) A good idea with a request like this would be to post a sample dwg with the block you want to check. use wblock to pull block out of an existing dwg. Edited Thursday at 12:57 AM by BIGAL Quote
Steven P Posted 10 hours ago Posted 10 hours ago This does blocks, but I can't remember why I stopped using it, think it was a speed thing. It BEdit each block to overkill, but since automated does it a lot quicker than manually open-close each block. Overkill settings are whatever you did last - no option to adjust settings in this script Might be a start for you to work from (defun c:OK-Ill ( / MySS) ;;Overkill by LISP (Batch processing...) (if (setq MySS (ssget "_x")) (command "-overkill" MySS "" "") ) ) (defun c:OK-BLOCKS ( / MySS acount MyEnt BlockName BlockList MyOption) (defun Blocklist (/ LL_Return) (vl-sort (vlax-for LL_Item (vla-get-blocks (vla-get-ActiveDocument (vlax-get-acad-object))) ;; can also do get-layers etc (if (equal (substr (vla-get-Name LL_item) 1 1) "\*") (progn ) (progn (setq LL_Return (cons (vla-get-Name LL_Item) LL_Return)) ) ; end progn ) ; end if ) ; end vlax-for '< ) LL_Return ) ; end defun (defun OKBlocks (BlockList / acount) (setq acount 0) (while (< acount (length BlockList)) (command "bedit" (nth acount Blocklist) ) (c:OK-ILL) (command "bsave") (command "bclose") (setq acount (+ acount 1)) ) ; end while ) ; end defun (initget "All Space") (setq MyOption (getkword "Select All Blocks or in this space (All or Space)")) (if (equal MyOption "Space") (progn (setq MySS (ssget "_X" '((0 . "INSERT")))) (setq acount 0) (setq BlockList (list)) (while (< acount (sslength MySS)) (setq MyEnt (entget (ssname MySS acount))) (setq Blockname (cdr (assoc 2 MyEnt))) (if (member Blockname BlockList) () (setq BlockList (cons Blockname BlockList)) ) (setq acount (+ acount 1)) ) ; end while ;;DO STUFF TO BLOCK LIST (OKBlocks BlockList) ) ; end progn (progn (OKBlocks (setq BlockList (BlockList))) ) ; end progn ) ; end if space (princ "\n")(princ (length BlockList))(princ " blocks assessed") (princ) ) Quote
SLW210 Posted 9 hours ago Posted 9 hours ago The full scope of what you are asking seems quite a lot to me. Thought, REFEDIT instead of BEDIT might be faster? I'm not sure about using BlockTableRecord, I'll have to look into that as well. Quote Skip Xrefs, layout blocks, anonymous/system blocks, and any block definitions that should not be modified. How would those items be separated from what does need OVERKILL? As for the last part, nothing is really being modified except to be cleaned up, so what exactly doesn't need cleaned and improved? I think LISP might be slow using commands compared to .NET or other methods, I might look into it if that's an option. Do you have an example drawing? How far have you got on writing this code? 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.