For what I understood, I know that an object can be deleted by running bpy.ops.object.delete() when that object is active.

But how can I verify that the object is deleted?

For example:

o = bpy.context.active_object # object I want to delete
print(is_deleted(o)) # False
print(is_deleted(o)) # True

What should I write in the function is_deleted?


1 Answer 1


I would do it by object name

def is_deleted(o):
    return not (o.name in bpy.data.objects)

# or instead of a function,
# obj will be None if the object isn't found, 
# else it returns the obj reference
obj = bpy.data.objects.get(o.name)  
  • $\begingroup$ Did you mean o.name not in bpy.data.objects? $\endgroup$
    – user16046
    Commented Jul 31, 2015 at 11:34
  • $\begingroup$ And what if the object is deleted and a new one with the same name is created before I perform the verification, would that be a problem? $\endgroup$
    – user16046
    Commented Jul 31, 2015 at 11:40
  • 2
    $\begingroup$ The delete operator is probably safer than removing objects via RNA methods. I don't know if it clears all references, but at least it won't fail if there are any users and I haven't seen any follow-up crashes unlike with RNA (which usually happens if users are cleared without clearing references). Other than that, I would do bpy.data.objects["name"] and catch a possible AttributeError, or use .objects.get("name") for performance reasons. BTW: it's impossible that a deletion occurs while your script is running, unless your script itself does that, because scripts run synchronous/blocking. $\endgroup$
    – CodeManX
    Commented Jul 31, 2015 at 18:24
  • 1
    $\begingroup$ Did you test this thoroughly? Because Blender will not crash before it actually tries to dereference an invalid reference (dangling pointer). As far as I understand, you would need to scan through each and every datablock and check if there's a reference to the object you wanna delete and clear it (set to None), then user count should drop to zero and the object can be safely deleted. $\endgroup$
    – CodeManX
    Commented Aug 2, 2015 at 9:25
  • 2
    $\begingroup$ I favour a succinct answer and have removed the extra noise. $\endgroup$
    – zeffii
    Commented Aug 2, 2015 at 10:29

You must log in to answer this question.