4

How to completely delete an object without using:

bpy.ops.object.delete()

bpy.ops methods are too slow for my script, so far I am able to delete an object with a simple:

del obj

But Blender does not reset/delete names of the deleted objects with this method, so I end up with Cube.344, Cube.599, etc..

Also, deleted objects are not linked to the scene.

David
  • 49,291
  • 38
  • 159
  • 317
VSB
  • 483
  • 1
  • 6
  • 22
  • 1
    Removing 1000 suzannes takes 0.011783123016357422 seconds (on my thinkpad). I think that's really fast. I guess you are using the operator in a loop, right? Also consider this comment – p2or Mar 11 '17 at 12:39
  • That is correct, operator in a loop for individual objects. – VSB Mar 11 '17 at 16:59
  • 3
    That's the reason why it takes so long... I'd suggest select all objects, then call the operator one time, this way it's safe and fast as well. – p2or Mar 11 '17 at 17:20
  • Updated my answer here: http://blender.stackexchange.com/a/27235/3710 – p2or Mar 15 '17 at 14:48
  • That is an acceptable option as long as I don't create new object data. – VSB Mar 15 '17 at 23:31
  • Not sure what you mean, I also added how to cleanup the data blocks... Can you elaborate? – p2or Mar 16 '17 at 07:43
  • There would be more memory usage if I copy object data without linking. Also, the object_name.XXX would not be incremental for the remaining objects at the end of the script. – VSB Mar 17 '17 at 20:15

1 Answers1

6

You are looking for the remove function.

import bpy
objs = bpy.data.objects
objs.remove(objs["Cube"], do_unlink=True)

The code above deletes an object named "Cube." The first parameter of the remove function is the object to remove, the second is a boolean about first unlinking the object (you want it set to True.)

batFINGER
  • 84,216
  • 10
  • 108
  • 233
David
  • 49,291
  • 38
  • 159
  • 317