3
$\begingroup$

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.

$\endgroup$
7
  • 1
    $\begingroup$ 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 $\endgroup$
    – p2or
    Mar 11, 2017 at 12:39
  • $\begingroup$ That is correct, operator in a loop for individual objects. $\endgroup$
    – VSB
    Mar 11, 2017 at 16:59
  • 3
    $\begingroup$ 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. $\endgroup$
    – p2or
    Mar 11, 2017 at 17:20
  • $\begingroup$ Updated my answer here: blender.stackexchange.com/a/27235/3710 $\endgroup$
    – p2or
    Mar 15, 2017 at 14:48
  • $\begingroup$ That is an acceptable option as long as I don't create new object data. $\endgroup$
    – VSB
    Mar 15, 2017 at 23:31

1 Answer 1

5
$\begingroup$

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

$\endgroup$
2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .