So i am not sure what happened here, but the story Is that I finished my script and it was working fine in UI and now I am running it using --background but something is broken now with deleting objects?
Using version 2.9 btw
script:
print(objectsToDelete)
for objectToDelete in objectsToDelete:
try:
if objectToDelete.type == 'MESH':
bpy.data.objects[objectToDelete.name].select_set(True)
bpy.ops.object.delete()
except:
print("")
output:
[bpy.data.objects['TR5_49'], bpy.data.objects['TR5_50'], bpy.data.objects['TR5_51'], bpy.data.objects['TR5_52'], bpy.data.objects['TR5_53'], bpy.data.objects['TR5_54'], bpy.data.objects['TR5_55'], bpy.data.objects['TR5_56'], bpy.data.objects['TR5_57'], bpy.data.objects['TR5_58'], bpy.data.objects['TR5_59'], bpy.data.objects['TR5_73'], bpy.data.objects['TR5_74'], bpy.data.objects['TR5_75'], bpy.data.objects['TR5_76'], bpy.data.objects['TR5_77'], bpy.data.objects['TR5_78'], bpy.data.objects['TR5_79'], bpy.data.objects['TR5_80'], bpy.data.objects['TR5_81'], bpy.data.objects['TR5_82'], bpy.data.objects['TR5_83'], bpy.data.objects['TR5_61'], bpy.data.objects['TR5_62'], bpy.data.objects['TR5_63'], bpy.data.objects['TR5_64'], bpy.data.objects['TR5_65'], bpy.data.objects['TR5_66'], bpy.data.objects['TR5_67'], bpy.data.objects['TR5_68'], bpy.data.objects['TR5_69'], bpy.data.objects['TR5_70'], bpy.data.objects['TR5_71'], bpy.data.objects['TR5_85'], bpy.data.objects['TR5_86'], bpy.data.objects['TR5_87'], bpy.data.objects['TR5_88'], bpy.data.objects['TR5_89'], bpy.data.objects['TR5_90'], bpy.data.objects['TR5_91'], bpy.data.objects['TR5_92'], bpy.data.objects['TR5_93'], bpy.data.objects['TR5_94'], bpy.data.objects['TR5_95']]
Info: Deleted 221 object(s)
Then it just goes ahead and deletes all objects in the scene!?
Length of the array is 44, so is this supposed to work differently when using --background? It's also doing this in the GUI now... which is really weird...
EDIT - Ehm, checking the selected objects crashes the program...
script:
if len(objectsToDelete) == len(bpy.context.selected_objects):
print("all objects selected")
bpy.ops.object.delete()
output:
Error : EXCEPTION_ACCESS_VIOLATION
Address : 0x00007FF67F5AAC78
Module : blender.exe
Thread : 00000c40
Writing: C:\Users\Recreate\AppData\Local\Temp\blender.crash.txt
Weird all of these seem to crash for me now...
bpy.data.objects.remove(objectToDelete)
#bpy.data.meshes.remove(objectToDelete.data)
#bpy.data.objects[objectToDelete.name].select_set(True)
bpy.data.objects.remove(ob_to_delete)https://blender.stackexchange.com/questions/27234/python-how-to-completely-remove-an-object?rq=1 – batFINGER Sep 21 '20 at 12:12obthen usingbpy.data.objects[ob.name]is longwindedly getting a reference toobwhich you have in the first place. – batFINGER Sep 21 '20 at 12:36while(remove_list): bpy.data.objects.remove(remove_list.pop())which will ensure list no longer contains ref to deleted object. – batFINGER Sep 21 '20 at 12:44