If I have an object “obj” how can I get a list of it’s children?
I notice that the object class has a “parent” property, I was hoping for a “children” property too, which would have been a list (potentially empty) of the objects children.
Sorry for the probably noobish question but I looked through google, the forum search and the python api reference index and couldn’t find the answer. Maybe I missed something obvious.
import bpy
def getChildren(myObject):
children = []
for ob in bpy.data.objects:
if ob.parent == myObject:
children.append(ob)
return children
#then if you have an object you find it's children by
myObject = bpy.data.objects['Cube']
children = getChildren(myObject)
for c in children:
print c.name
Thanks for that answer, it helped me alot.
I just want to give an advise from what i learned while scripting with Blender.
There is not really a need to loop through all bpy.data.objects to get the children of a given object.
If the object has children the children are already stored in a collection inside the object.
you can get it like this:
lets say your object is a cube.
myObject = Cube
you can do:
for child in myObject.children:
print(child.name) #or do what you need to do with the child object…