0
$\begingroup$

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"...

$\endgroup$
1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.