Access Orphaned Object/Data

Hi,

Is there a way to access an Orphan Object?

When I tried bpy.data.objects['Object_Name],
it gives me an error of
KeyError: 'bpy_prop_collection[key]: key "Object_Name" not found'

I’m trying to link the orphan objects back to the scene.

Is there a way around this?

1 Like

Thanks for asking. I was just about to write the exact same question.

Blender 2.81a

@bentraje, did you find a solution in the meantime?

Unlinking an object from all collections seems to automatically destroy it. Try: [m.name for m in bpy.data.meshes if m.users == 0] to list all orphaned meshes.

1 Like

@ambi

Thanks for the response. It does help me access the orphan data.
Just one thing, is there a way to recall the previous translation and rotation values of the orphan mesh? Currently, when I relink it again, it snaps back to the world origin.

Here is my working code:

import bpy

orphan_list = [m for m in bpy.data.meshes if m.users == 0]
col = bpy.data.collections[0]

for orphan in orphan_list:
    object = bpy.data.objects.new(orphan.name, orphan)
    col.objects.link(object)

@mj84

Apologies for the late response.
The code above helps you relink the orphan mesh back to the collection

As far as I’m aware, objects store transformation information, not meshes. So if you delete objects, you also delete the information required to translate and rotate.

@ambi
Just to confirm. So there’s no way to retrieve them once deleted?
Or are there any other method of deleting an object and retain its transformation?