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.
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():
rs.UnselectAllObjects()
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:
explode_em([z])
rs.UnselectAllObjects()
for block in x:
rs.DeleteBlock(block)
RemoveAllBlocks()
@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