# Is it possible, with Python, to select an object by its scene graph path alone?

So I've been a programmer for a long time, and a modeler for a while now, and I've just gotten started on using Python in Blender. One thing bugs me about the interface and I'm hoping I'm just overlooking it.

To select an object of name 'Sphere', we would use code like this:

bpy.data.objects['Sphere']


And if 'Sphere' has a single child object, named, say, 'Cube', then we would do this:

bpy.data.objects['Sphere'].children[0]


but unfortunately, this would not work:

bpy.data.objects['Sphere'].children('Cube')


Nor this, which would be even more ideal:

bpy.data.objects['Sphere/Cube']


However, this would still work:

bpy.data.objects['Cube']


with the additional restraint that no two objects, regardless of relative location, can have the same name.

Is it even possible to find something by scene graph path like that?

• Usually via scene references: either bpy.context.scene.objects['Cube'] or bpy.context.scene.objects.get("Cube"). Consider if you run it, there is nothing selected it is just a reference. Also they can not have the same name even one of them is the parent object (try it and you'll see). What do you mean by scene graph? Can you please eleborate? Btw: Object selection in the 3d view: blender.stackexchange.com/a/132829/31447 – brockmann Sep 9 '19 at 18:57
• Sure, I can elaborate. The scene graph is a term used, in some contexts more familiar to me, to refer to the scene tree. In OpenGL, as an example, you typically have a root, any number of transform objects beneath it, and finally mesh data. (I'm aware that this is a simplification.) However, it takes on a tree-like structure, and given that my example Sphere was top-level, I can often refer to its child as '/Sphere/Cube', like a file path relative to the scene graph. Is that possible, at all, in Blender? – Michael Eric Oberlin Sep 9 '19 at 19:12