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