Finding children of object

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
Posts: 0
Joined: Mon Apr 24, 2006 9:16 pm

Finding children of object

Post by draco » Mon Apr 24, 2006 9:38 pm

Is there a way to obtain object children in python script ?
I'm searching for some functionality similar to blender select->grouped->children command. It shouldn't select objects but just return them of course :)

Posts: 9
Joined: Wed Oct 23, 2002 8:32 pm

Post by Ben » Tue Apr 25, 2006 9:23 pm

Code: Select all

def getChildren(Myobj):
     for obj in Blender.Objects.Get():
          pare = obj.getParent()
          if ==
                return obj    
obj is the children of Myobj

Posts: 0
Joined: Mon Apr 24, 2006 9:16 pm

Post by draco » Tue Apr 25, 2006 11:02 pm

I thought that there should be some direct way to obtain object children, but you're right, it will do what i want.
Thanks :)

Posts: 0
Joined: Tue Aug 05, 2003 7:58 am
Location: 45N 86W

Post by stiv » Tue Apr 25, 2006 11:25 pm

A blender Object does not keep a list of its children. (what a harsh world when parents do not know their children!) But luckily, children do know their parents.

Unless I am even more blind than usual, Ben's code snippet only returns the first child object. You could replace the body of his func with something like this to get a more complete list:

return [ob for ob in Object.Get() if ob.parent == myObj ]

Posts: 0
Joined: Wed Mar 17, 2004 5:20 pm

Post by an-toni » Wed Apr 26, 2006 2:04 pm

the version i did at orange seems to be: (from )

Code: Select all

def getChildren(ob, scene): #does not scale. fix api.
	def isParent(ob, c):
		p = c.getParent()
		if p is not None: 
			if ==
				return True
	return [c for c in scene.getChildren()
			if isParent(ob, c)]
works, dunno if is optimal. and dont know if the comment (fix api) makes sense, as like Stivs said the info is not there.. (and list comprehensions are looped in C so i dont know if a c-written version would be sig. faster. i did not have probs with the speed of this)


Post Reply