Explode 'parent' blocks without exploding nested blocks

Explode 'parent' blocks without exploding nested blocks

gary.smithP6ELJ
Explorer Explorer
2,822 Views
11 Replies
Message 1 of 12

Explode 'parent' blocks without exploding nested blocks

gary.smithP6ELJ
Explorer
Explorer

I have a 3D model assembly saved as a STEP file created in a different 3D CAD application (Creo).  When I import the model into AutoCAD it comes in fine, but all assemblies and sub-assemblies from the original model come in as blocks and nested blocks.

 

I need to explode all the 'parent' blocks, but keep the lowest level nested blocks as blocks.

 

This can be done manually, but sometimes there are a number of levels of nested blocks and it's not clear in AutoCAD how many levels there are.. so you never know when you've exploded the lowest level block until the properties state 'surface' or '3D solid'.  There is also a lot of assemblies (nests) in the model and I have a few models to apply this to!

 

I've seen there are ways of exploding only nested blocks, but this is the opposite to what I want to do.  'Burst' is not necessary as there are no attributes in the blocks.

 

Anyone ever tried this?

0 Likes
Accepted solutions (1)
2,823 Views
11 Replies
Replies (11)
Message 2 of 12

Moshe-A
Mentor
Mentor

@gary.smithP6ELJ  hi,

 

1. EXPLODE command always disassembles the most outer block (keeping the nested)

2. REFEDIT command can give you the nesting tree of any block/xref

 

Moshe

 

 

0 Likes
Message 3 of 12

cadffm
Consultant
Consultant

Hi,

 

I am pretty sure you will find tools what do that, so: Search on!

I can't test for you, but _giles code sounds good

https://forums.autodesk.com/t5/net/un-nest-blocks-in-entire-drawing/td-p/12174867

 

LeeMac offers a UnnestBlock function for (single) manually selection,

it should be easy to use this code for your need in Lisp.

 

and so on..

 

HTH

 

Sebastian

0 Likes
Message 4 of 12

gary.smithP6ELJ
Explorer
Explorer

Thanks for taking the time to help - much appreciated.

 

I've tried LeeMac's UnnestBlock function, but it looks like I need to select the nested block in order to unnest which means I have to open the nest in the first instance.. clearly I need to look into this further.

0 Likes
Message 5 of 12

Moshe-A
Mentor
Mentor

@gary.smithP6ELJ ,

 

What i am missing here?

say you have 3 blocks (a,b,c) and C is nest in B and B is nest in A...you want to explode A + B but keep C the lowest?

 

Moshe

 

0 Likes
Message 6 of 12

cadffm
Consultant
Consultant

>"say you have 3 blocks (a,b,c) and C is nest in B and B is nest in A...you want to explode A + B but keep C the lowest?"

How I understood the situation:

If you have no other objects than the inserts in Block B and C, I would say Yes.

 

But let's say you have (just one) insert of BlockC - but in theory you can have more than one.

Say you have 3 blocks (a,b,c) and C hat a circle, and is nest in B, what have also a line object, and B is nest in A, what have also a Text:

Then you don't explode any insert and the result in modelspace should be:

1x InsertA, position at "the same place on modelspace" as before

1x InsertB, position at "the same place on modelspace" as before

1x InsertC, position at "the same place on modelspace" as before

BlockA has a Text

BlockB has a Line

BlockC has a Circle

 

Result: No single Objecs in Modelspace, just inserts and no block incl. another insert.

 

Easy by copyobjects from userblock to modelspace, but blocks can be used multiple times in different blocks,

so you had to check all placements first / before delete the insert from a blockdefinition

 

Sebastian

0 Likes
Message 7 of 12

Moshe-A
Mentor
Mentor

@cadffm ,

 

So in short we could say disassemble a complex nest block? but than lets look at what OP said:

"I need to explode all the 'parent' blocks, but keep the lowest level nested blocks as blocks"

does this settle with what you said?!

 

we need to 'hear' OP again 😀

 

Moshe

 

 

 

 

Message 8 of 12

cadffm
Consultant
Consultant

@Moshe-A 

"So in short we could say disassemble a complex nest block"

If you can express yourself well in English, then you can say it like that. (I couldn't 🤣)

 

But of course, perhaps he like to explode all, except if the insert(block) does not contain any inserts.

What is like you said with the simple A, B, C example, with blocks who contains nothing than inserts.

 

thumb up

 

@gary.smithP6ELJ 

It's your turn now.

Sebastian

0 Likes
Message 9 of 12

gary.smithP6ELJ
Explorer
Explorer

Thank you both for your input and sorry for my delayed reply - I think different time zones and working hours are to blame! 🙂

 

>"say you have 3 blocks (a,b,c) and C is nest in B and B is nest in A...you want to explode A + B but keep C the lowest?"

 

This is correct - in this case A and B are just acting as containers for block C.  I only want the lowest level blocks kept as blocks - in this case C, but in some cases there will only be two levels, A and B and in this case I just want the lowest level B kept as a block.

 

The attached screenshot shows a real example..

 

You can see that there are a number of C blocks nested in B block, which is nested in A block.  I only want the C blocks as they are the lowest level blocks.  The entire drawing will then contain only blocks (with no nests at all).

0 Likes
Message 10 of 12

marko_ribar
Advisor
Advisor
Accepted solution

Time to post a code...

Not tested with dynamic blocks, but with normal ones it passed my tests...

 

(defun c:explallbutnest ( / *error* chkparent ss2ents cmd ss i l )

  (defun *error* ( m )
    (if (= 8 (logand 8 (getvar (quote undoctl))))
      (if command-s
        (command-s "_.undo" "_e")
        (vl-cmdf "_.undo" "_e")
      )
    )
    (if cmd
      (setvar (quote cmdecho) cmd)
    )
    (if m
      (prompt m)
    )
    (princ)
  )

  (defun chkparent ( b / e f )
    (setq e (tblobjname "BLOCK" (cdr (assoc 2 (entget b)))))
    (while (setq e (entnext e))
      (if (= (cdr (assoc 0 (entget e))) "INSERT")
        (setq f t)
      )
    )
    f
  )

  (defun ss2ents ( ss / l )
    (if ss
      (repeat (setq i (sslength ss))
        (setq l (cons (ssname ss (setq i (1- i))) l))
      )
    )
    l
  )

  (setq cmd (getvar (quote cmdecho)))
  (setvar (quote cmdecho) 0)
  (if (= 8 (logand 8 (getvar (quote undoctl))))
    (vl-cmdf "_.undo" "_e")
  )
  (vl-cmdf "_.undo" "_g")
  (if (setq ss (ssget "_X" (list (cons 0 "INSERT"))))
    (progn
      (setq l (ss2ents ss))
      (while (vl-some (function (lambda ( x ) (chkparent x))) l)
        (foreach b l
          (if (chkparent b)
            (progn
              (vl-cmdf "_.explode" b)
              (while (< 0 (getvar (quote cmdactive)))
                (vl-cmdf "")
              )
            )
          )
        )
        (setq ss (ssget "_X" (list (cons 0 "INSERT"))))
        (setq l (ss2ents ss))
      )
    )
  )
  (*error* nil)
)

 

HTH.

M.R.

Marko Ribar, d.i.a. (graduated engineer of architecture)
Message 11 of 12

cadffm
Consultant
Consultant

Nice,  without a minute of coding, I got a function what I can use in future perhaps.

Side by side to my ExplNestedBlocks function, perfect.

 

@gary.smithP6ELJ 

?

Sebastian

Message 12 of 12

gary.smithP6ELJ
Explorer
Explorer

@marko_ribar 

 

Amazing, that's absolutely brilliant and it works perfectly! 😀

 

Thank you for taking the time to write this and thanks to all contributors to this thread - so much for me to learn here!

0 Likes