I have a python file I am using in blender to load up an old file another script saved previously using save_as_mainfile(). I want to delete some objects from the scene, but for the purpose of this question I will try to delete them all. Here is the code.
bpy.ops.wm.open_mainfile(filepath=filename)
bpy.ops.object.select_all(action='DESELECT')
for ob in bpy.data.objects:
ob.select = True
result = bpy.ops.object.delete()
print("{} objects remain because results={}".format(len(bpy.data.objects), result))
The result of running this is "35 objects remain because results={'CANCELLED'}" .. I do not know why the operation was cancelled, and I am hoping the len is 0. I have checked and I am in OBJECT mode (indeed trying to change modes gave me a poll error of some kind).
Thanks.