I have a problem with a Rhino Python script which should explode all blocks and delete the blocks.
In Rhino 7 this script part worked very reliably.
all_objects = rs.AllObjects()
for obj_id in all_objects:
if rs.ObjectType(obj_id) == 4096: #this line throws the error
rs.Command('_-ExplodeBlock "{}" _Delete'.format(obj_id))
In Rhino 8 there is always an error “Object does not exist in Object Table”, for details see attached picture.
The ID you’re trying to delete doesn’t exist anymore because the the ID of the geometry added by the ExplodeBlock is different that he ID of block instance that was there.
Maybe this works for you?
rs.Command("_-ExplodeBlock _AllBlocks")
for bn in rs.BlockNames():
rs.DeleteBlock(bn)