Convert Block Instances into Groups

Convert Block Instances into Groups

koolestani
Explorer Explorer
1,020 Views
12 Replies
Message 1 of 13

Convert Block Instances into Groups

koolestani
Explorer
Explorer

Hi

Is there any way to convert all instances of a block in a drawing into groups? The contents of these blocks have to preserve their properties either defined "by layer" or overridden and stay in their place (preserve their location in the drawing).

0 Likes
1,021 Views
12 Replies
Replies (12)
Message 2 of 13

imadHabash
Mentor
Mentor

Hi, 

It's Not applicable in normal and existing CAD commands.. you may need an outsource plugin or a lisp to do that.

 

 

Imad Habash

EESignature

0 Likes
Message 3 of 13

koolestani
Explorer
Explorer

That's fine by me. Is there any LISP routine that can achieve this?

0 Likes
Message 4 of 13

Michiel.Valcke
Advisor
Advisor

Hi @koolestani 

The people at the customization boards can probably help you better. After looking online I found a few lisp routines to change groups to blocks but not the other way around. 

To what end do you need groups over blocks?

0 Likes
Message 5 of 13

martin_leiter
Advocate
Advocate

Hello Choolestani

You'll find it here, express tools are required

 

https://ww3.cad.de/foren/ubb/Forum145/HTML/003169.shtml#000003

0 Likes
Message 6 of 13

Kent1Cooper
Consultant
Consultant

@koolestani wrote:

.... The contents of these blocks have to preserve their properties either defined "by layer" or overridden ....


And if pieces in a Block definition were drawn on Layer 0, do they need to be that way in the eventual Group, or should they take on the Layer that their containing Block insertion was on?  If the former, it should be rather simple, since after an Explode, the pieces will be the Previous selection, to be fed to a Group command.

 

Unnamed Groups, or should they be given names?

 

Any Attributes involved?

Kent Cooper, AIA
0 Likes
Message 7 of 13

koolestani
Explorer
Explorer

@Kent1Cooper If I understand your question correctly I'll say the former is what needs to happen. Yes, the groups can be unnamed, with no attributes involved. 

0 Likes
Message 8 of 13

koolestani
Explorer
Explorer

Thank you for the suggestion, I'll take care in the future! This may sound really silly but the objective was to purge blocks to eliminate the possibility of some layers that I cannot delete being referenced within said blocks. Since the block definitions inside the drawing were a hot mess and I was trying to simplify things a bit.

0 Likes
Message 9 of 13

koolestani
Explorer
Explorer

Thanks for the reply. The contents of the referenced page seem too hard for me to comprehend.

0 Likes
Message 10 of 13

TomBeauford
Advisor
Advisor

Try entering SetNestedObjectsByBlock at the command line and selecting a block.

https://www.reddit.com/r/AutoCAD/comments/mgfzhc/best_way_to_nuke_a_masterplan_and_make_it_gray/

64bit AutoCAD Map & Civil 3D 2023
Architecture Engineering & Construction Collection
2023
Windows 10 Dell i7-12850HX 2.1 Ghz 12GB NVIDIA RTX A3000 12GB Graphics Adapter
0 Likes
Message 11 of 13

Kent1Cooper
Consultant
Consultant

@koolestani wrote:

... the former is what needs to happen. Yes, the groups can be unnamed, with no attributes involved. 


This seems to do that, in limited testing:

(defun C:B2G ; = Blocks {to} Groups
  (/ bsel bdata bname ct bss n blk)
  (if
    (and
      (setq bsel (entsel "\nSelect Block to have all instances turned into Groups: "))
      (= (cdr (assoc 0 (setq bdata (entget (car bsel))))) "INSERT")
      (not (assoc 1 (tblsearch "block" (setq bname (cdr (assoc 2 bdata)))))); not Xref
    ); and
    (progn ; then
      (setq ct (getvar 'ctab))
      (setq bss (ssget "_X" (list '(0 . "INSERT") (cons 2 bname))))
      (repeat (setq n (sslength bss))
        (setq blk (ssname bss (setq n (1- n))))
        (setvar 'ctab (cdr (assoc 410 (entget blk))))
        (command "_.explode" blk)
        (initcommandversion)
        (command "_.group" (ssget "_P") "")
      ); repeat
      (setvar 'ctab ct)
    ); progn
  ); if
  (princ)
); defun 

It gets them in all Model/Layout spaces.  It relies on the Block in question being defined to allow Exploding, but if that can't be relied on, it could be made to check for that, and if it's not, either change that or ask the User whether to change that.  It also expects that all insertions will be on unlocked and thawed/on Layers, but those possibilities could be accounted for.

 

It could be made to suppress command echoing, have *error* handling to ensure resetting stuff, put an Undo begin/end wrapping around it all, etc., but first see whether it does what you're after.

Kent Cooper, AIA
Message 12 of 13

koolestani
Explorer
Explorer

Thank you @Kent1Cooper, this works perfectly! Sorry for the late response. Your remarks about Undo capabilities and error handling features are spot on, I would love to see those bells and whiles added to this routine. The groups being named or unnamed isn't a problem for me, I actually had no idea that groups can be named, but might as well include that facility if possible.

0 Likes
Message 13 of 13

koolestani
Explorer
Explorer

Hey, @Kent1Cooper, could you find the time to add these finishing touches? Just checking up. It's still a great script,  thank you for your help!

0 Likes