Overkill ALL Blocks

Overkill ALL Blocks

jlaidle1
Advocate Advocate
11,823 Views
29 Replies
Message 1 of 30

Overkill ALL Blocks

jlaidle1
Advocate
Advocate

Is there a way with LISP to run the overkill command with all blocks in a drawing?

 

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Accepted solutions (1)
11,824 Views
29 Replies
Replies (29)
Message 2 of 30

dbhunia
Advisor
Advisor

Hi,

 

Try this.........

 

(defun C:OKB (/ sset)
(command "_.CMDECHO" 0)
(setq sset (ssget "_X" (List '(0 . "INSERT"))));;;Select onlo Blocks
(command "_.-OVERKILL" sset "" "_done")
(command "_.CMDECHO" 1)
(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 30

jlaidle1
Advocate
Advocate

That is not working, overkill needs to be run inside the blocks.  For example, with block editor.

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 4 of 30

marko_ribar
Advisor
Advisor

See if this can be of any help...

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/cannot-delete-duplicate-objects/m-p/...

 

Regards...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 5 of 30

jlaidle1
Advocate
Advocate

That deletes duplicate blocks, not duplicate objects within blocks.

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 6 of 30

ВeekeeCZ
Consultant
Consultant

Try this and see if this doesn't kill your computer... This should be better than multiple Open/Close Block Editor...

Edit: It only except blocks with en entity at the insertion point...

 

(defun c:OverkillInBlocks ( / ss i)
  (if (setq ss (ssget '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
      (command "_.-REFEDIT" (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))) "_o" "_a" "_y"
               "_.-OVERKILL" "_all" "" "_Done"
               "_.REFCLOSE")
      (while (> (getvar 'CMDACTIVE) 0)
	(command "_save"))))
  (princ)
)

 

0 Likes
Message 7 of 30

marko_ribar
Advisor
Advisor

@ВeekeeCZ

 

I already taked with you ab REFEDIT-ing block by picking insertion point... This is incorrect - (cdr (assoc 10 (entget bl)))... If you remember I did research on the theme refeditbyname and although it's possible to add POINT entity to block at insertion point of block do refedit and at the end remove point, it is not recommended to do this at all... Block may already have point inside and as you mentioned it is slow method and not so reliable... If it's not possible to do this task - overkill by BEDIT, then don't do it at all... It should be a lesson for OP future job not to duplicate entities inside blocks, I can say only that this is slappy and cumbersome work from anyone that is using AutoCAD... If you want to be professional in your work you have to do things that have sense and practice to be better every day until practise become your experise...

Marko Ribar, d.i.a. (graduated engineer of architecture)
0 Likes
Message 8 of 30

jlaidle1
Advocate
Advocate

This doesn't seem to be working, see below.  Also, my test drawing does not have any locked layers.

 

2018-11-13_9-23-38.jpg

 

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 9 of 30

ВeekeeCZ
Consultant
Consultant

Yeah... you're right. My bad, I forgot about it. Thanks for reminding me...

But maybe @jlaidle1 have all blocks of a rectangle shape. Edit: Well, he has not.

 

 

0 Likes
Message 10 of 30

jlaidle1
Advocate
Advocate

Excellent point, but our company has 100's of users and most of them do not use best practices.

Also, we get DWG's from suppliers that don't use best practices.  So i'm trying to make an 'easy button' for our users to easily clean up blocks that have overlapping / segmented and duplicate objects.

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 11 of 30

jlaidle1
Advocate
Advocate

Using other lisp applications from this forum, but it doesn't do anything.  So, might be getting closer.

Any thoughts?

 

(defun c:CleanBlocks ( / getSubEnt ss i ent ename blkGeom ssBlkDef)

(defun getSubEnt ( ent / ss etype)
(setq ss (ssadd))
(while (setq ent (entnext ent))
(setq etype (assoc 0 (entget ent)))
(if (and (/= etype "BLOCK")(/= etype "ATTDEF"))
(setq ss (ssadd ent ss))
);while
);defun
ss
);defun getSubEnt

(setq ssBlkDef (ssget "X" (list '(0 . "BLOCK"))))
(setq i 0)

(if ss
(while (< i (sslength ss))
(setq ent (entget (ssname ss i)))
(setq ename (cdr (assoc 2 ent)))

(command "bedit" ename)
(command "_.-OVERKILL" "_all" "" "_Done")

(initcommandversion)
(command "_.bclose" "_sav")
(setq i (1+ i))
);while
(princ)

);if
);defun

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 12 of 30

jlaidle1
Advocate
Advocate

Current code, but nothing happens:

 

(defun c:CleanBlocks ( / getSubEnt ss i ent ename blkGeom ssBlkDef)

(defun getSubEnt ( ent / ss etype)
(setq ss (ssadd))
(while (setq ent (entnext ent))
(setq etype (assoc 0 (entget ent)))

(if (and (/= etype "BLOCK")(/= etype "ATTDEF"))
(setq ss (ssadd ent ss))
);if
);while

ss
);defun getSubEnt

(setq ssBlkDef (ssget "X" (list '(0 . "BLOCK"))))

(setq i 0)

(if ss
(while (< i (sslength ss))
(setq ent (entget (ssname ss i)))
(setq ename (cdr (assoc 2 ent)))

(command "bedit" ename)

(setq blkGeom (getSubEnt (ssname ss i)))

(if blkGeom
(command "_.-OVERKILL" blkGeom "" "_Done")
);if

(initcommandversion 1)
(command "_.bclose" "_sav")
(setq i (1+ i))
);while
(princ)
);if
);defun

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 13 of 30

ВeekeeCZ
Consultant
Consultant

Hmm... it would be really slow...

 

(defun c:OverkillInBlocks ( / ss i)
  (if (setq ss (ssget '((0 . "INSERT"))))
    (repeat (setq i (sslength ss))
      (command "_.-BEDIT" (cdr (assoc 2 (entget (ssname ss (setq i (1- i))))))
               "_.-OVERKILL" "_all" "" "_Done"
               "_.BCLOSE")
      (while (> (getvar 'CMDACTIVE) 0)
	(command "_save"))))
  (princ)
)
0 Likes
Message 14 of 30

dlanorh
Advisor
Advisor
Concept only.
Get a list of blocks in block table
start foreach
Insert block at (0.0 0.0 0.0) using (setq obj (vla-insertblock...)
make sure explodeable property is true
get bounding box of block
zoom window using bounding box (vla-zoomwindow a_app ll ur)
explode block
overkill using crossing bounding box
redefine block using commandline version and crossing boundingbox

works on the command line with blocks i've tested including blocks with attributes

I am not one of the robots you're looking for

0 Likes
Message 15 of 30

dlanorh
Advisor
Advisor

Oops!! didn't think about dynamic blocks. Robot Embarassed

I am not one of the robots you're looking for

0 Likes
Message 16 of 30

jlaidle1
Advocate
Advocate

That works, but its prompting for the selection of the blocks.

I type all and it works.  Your code has 'all' in it, but its not recognizing it.

 

(defun c:OverkillBlocks ( / ss i)
(if (setq ss (ssget '((0 . "INSERT"))))
(repeat (setq i (sslength ss))
(command "_.-BEDIT" (cdr (assoc 2 (entget (ssname ss (setq i (1- i))))))
"_.-OVERKILL" "_all" "" "_Done"
"_.BCLOSE")
(while (> (getvar 'CMDACTIVE) 0)
(command "_save"))))
(princ)
)

John Laidler
ITO - Application Management


Please use "Accept as Solution" & give "Kudos" if this response helped you.

0 Likes
Message 17 of 30

dbhunia
Advisor
Advisor

Hi

 

use this

(defun c:OverkillBlocks ( / ss i)
(setq CMD (getvar "CMDECHO"))
(setvar "CMDECHO" 0)
(if (setq ss (ssget "_X" '((0 . "INSERT"))))
	(repeat (setq i (sslength ss))
		(command "_.-BEDIT" (cdr (assoc 2 (entget (ssname ss (setq i (1- i))))))
			"_.-OVERKILL" "_all" "" "_Done"
			"_.BCLOSE")
		(while (> (getvar 'CMDACTIVE) 0)
			(command "_save")
		)
	)
)
(setvar "CMDECHO" CMD)
(princ)
)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 18 of 30

dlanorh
Advisor
Advisor
Not my code but @ВeekeeCZ 's

I am not one of the robots you're looking for

0 Likes
Message 19 of 30

ВeekeeCZ
Consultant
Consultant
Accepted solution

Hmm, that was just a concept. I was hoping that you will test it on a larger amount of selected blocks and don't hack your computer by doing that - not best experience with this approach.

 

I would definitely not recommend adding just "X"...

The selection needs to be improved much better to exclude all xrefs, arraypath, better all dynamic blocks and its references, then all blocks process just once, not each reference... and so on.

 

(vl-load-com)

(defun c:OverkillInBlocks ( / *error* adoc lst next)

  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (vla-endundomark adoc)
    (princ))
  
  (vla-startundomark (setq adoc (vla-get-activedocument (vlax-get-acad-object))))
  
  (vlax-for blk (vla-get-blocks adoc)
    (if (and (= 0 (vlax-get blk 'islayout))
             (= 0 (vlax-get blk 'isdynamicblock))
             (= 0 (vlax-get blk 'isxref))
             (vlax-write-enabled-p blk)
             (not (wcmatch (vla-get-Name blk) "`*@*"))
             )
      (setq lst (cons (vla-get-Name blk) lst))))
  
  (foreach n lst
    (command "_.-BEDIT" n)
    (if (not next)
      (command "_.OVERKILL" "_all" "")
      (command "_.-OVERKILL" "_all" "" "_Done"))
    (command "_.BCLOSE")
    (while (> (getvar 'CMDACTIVE) 0)
      (command "_save"))
    (setq next T))
  
  (if lst (princ (strcat "\n" (itoa (length lst)) " blocks cleaned.")))
  (*error* "end")
  )

 

Message 20 of 30

ВeekeeCZ
Consultant
Consultant

@jlaidle1 wrote:

...

I type all and it works.  Your code has 'all' in it, but its not recognizing it.

 

(defun c:OverkillBlocks ( / ss i)
...
"_.-OVERKILL" "_all" "" "_Done"
"_.BCLOSE")
...


 

It dose. It selects ALL entities within the Block Editor.

0 Likes