0

I try to delete all meshes I made by putting together about all I could find from this question , using this code:

def delete_things(spec_type):
        oldMode = bpy.context.mode
        bpy.ops.object.mode_set(mode='OBJECT')
        bpy.ops.object.select_all(action='DESELECT')
        for o in bpy.data.objects:
            if o.type == spec_type:
                o.select = True
            else:
                o.select = False
        bpy.ops.object.delete()
        bpy.ops.object.mode_set(mode=oldMode)
        bpy.ops.wm.save_as_mainfile(filepath=bpy.data.filepath)
        bpy.ops.wm.open_mainfile(filepath=bpy.data.filepath)

def delete_all_mesh():
    delete_things('MESH')

delete_all_mesh()

I thought I made sure to set the right mode, still I get the error " bpy.ops.object.mode_set.poll() failed, context is incorrect"...

Gnub
  • 455
  • 1
  • 4
  • 13

1 Answers1

1

The error you are receiving is due to the fact your trying to change the object mode when no objects exist, because you've deleted them all.

cmomoney
  • 2,660
  • 12
  • 17