"Batch Delete" for All Block Definitions in Block Manager?

Is there any way to delete all the block definitions in the Block Manager with one wave of the wand?

The only method that seems possible is to RMB on each one—one at a time—then delete the definition.

(Good fun when working on a Solidworks file with hundreds of block definitions, including all the screws and bolts!)

Related Wish: it would be pretty neat if Rhino could detect if a block is exploded, and no longer in use; Rhino would automatically delete that block in the Block Manager.



Use the purge command

Here’s a Python that will nuke all blocks and turn any existing instances into regular objects. It asks no questions, it just does it…

import rhinoscriptsyntax as rs

def RemoveAllBlocks():
    x = rs.BlockNames()
    if not x: return
    y = rs.ObjectsByType(4096)
    if y:
        def explode_em(blocks):
            for Id in blocks:
                if rs.IsBlockInstance(Id):
                    blocks = rs.ExplodeBlockInstance(Id)
                    if blocks: explode_em(blocks)
        for z in y: 
    for block in x:



@wim: Thanks! Worked well once all blocks were exploded.

@pascal: Thanks! This also worked once all blocks were exploded. I tried running this script after opening the Solidworks STEP file, before exploding all blocks, but no luck. Is it supposed to work in this fashion?

If so, here’s the error message I got running the script in Atom. Perhaps this relates to nested blocks (which the file does have)? ~Dave

Hmm - I’ll check - I tested it on nested blocks but only a simple example.

Hmm- worked here on a complex step file. Maybe a Windows/Mac thing to check, I’ll poke around the support files listed in the error message.

@DigiFabLab - it worked here from Atom, with nested blocks. Can you post or private message me with a (simple, if possible) file for which it fails?



Just PM’d you with the file. ~Dave

Hey! Thanks for the script! Is it possible to do the same with only referenced blocks? I just can’t get rid of them in the BlockManager.


Thank you so much! You’re a lifesaver.

It works! This was my first use of a script- Im buzzing out! Thanks Pascal!

is it possible to replace the command rs.ExplodeBlockInstance(Id) with the ExplodeBlocksToLayers

yes, basically you can run any command from within a script with rs.Command()
Does this solve what you want to achieve?