Python API: add "children_recursive" property to Object & Collection
This is a convenience property, already available for bones. Simplifies D13821 which in-lined this function.
This commit is contained in:
parent
cea588b9ef
commit
7c568e7d36
|
@ -100,6 +100,19 @@ class Texture(bpy_types.ID):
|
|||
class Collection(bpy_types.ID):
|
||||
__slots__ = ()
|
||||
|
||||
@property
|
||||
def children_recursive(self):
|
||||
"""A list of all children from this collection."""
|
||||
children_recursive = []
|
||||
|
||||
def recurse(parent):
|
||||
for child in parent.children:
|
||||
children_recursive.append(child)
|
||||
recurse(child)
|
||||
|
||||
recurse(self)
|
||||
return children_recursive
|
||||
|
||||
@property
|
||||
def users_dupli_group(self):
|
||||
"""The collection instance objects this collection is used in"""
|
||||
|
@ -120,6 +133,27 @@ class Object(bpy_types.ID):
|
|||
return tuple(child for child in bpy.data.objects
|
||||
if child.parent == self)
|
||||
|
||||
@property
|
||||
def children_recursive(self):
|
||||
"""A list of all children from this object.
|
||||
|
||||
.. note:: Takes ``O(len(bpy.data.objects))`` time."""
|
||||
import bpy
|
||||
parent_child_map = {}
|
||||
for child in bpy.data.objects:
|
||||
if (parent := child.parent) is not None:
|
||||
parent_child_map.setdefault(parent, []).append(child)
|
||||
|
||||
children_recursive = []
|
||||
|
||||
def recurse(parent):
|
||||
for child in parent_child_map.get(parent, ()):
|
||||
children_recursive.append(child)
|
||||
recurse(child)
|
||||
|
||||
recurse(self)
|
||||
return children_recursive
|
||||
|
||||
@property
|
||||
def users_collection(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue