pymel.util.trees.MetaTree

digraph inheritancee2f0d8591c {
rankdir=TB;
ranksep=0.15;
nodesep=0.15;
size="8.0, 12.0";
  "MetaTree" [fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,URL="#pymel.util.trees.MetaTree",style="setlinewidth(0.5)",height=0.25,shape=box,fontsize=8];
}

class MetaTree

This metaclass defines the type of all ‘tree’ classes

class ImTree

The methods for an immutable Tree class.

breadth()
Breadth first traversal of a tree.
child(index=0)
Returns nth child (by default first), is it exists
copy(cls=None)
Shallow copy of a tree. An extra class argument can be given to copy with a different (tree) class. No checks are made on the class.
debug(depth=0)
Returns an detailed representation of the tree fro debug purposes
depth()
Depth of self, the distance to self’s root
dist(element, **kwargs)
Returns distance from self to element, 0 means self==element, None if no path exists up keyword set to True means it will search ascendants(parent and parents of parent) self for element, default is False down keyword set to True means it will search descendants(childs and childs of childs) of self for element, default is False If neither up nor down is specified, will search both directions signed keyword set to true means returns negative distance when element is upwards self, positive when it’s downwards
formatted(returnList=False)
Returns an indented string representation of the tree
height()
Get maximum downward depth (distance from element to furthest leaf downwards of it) of the tree
leaves()
Get an iterator on all leaves under self
level(dist=0)
Get an iterator on all elements at the specified distance of self, negative distance means up, positive means down
parents()
Returns an iterator on path from element to top root, starting with first parent, empty iterator means self is root
path(element=None, **kwargs)
Returns an iterator of the path to specified element if found, including starting element, empty iterator means no path found. For trees where duplicate values are allowed, shortest path to an element of this value is returned. element can be an ancestor or a descendant of self, if no element is specified, will return path from self’s root to self up keyword set to True means it will search ascendants(parent and parents of parent) self for element, default is False down keyword set to True means it will search descendants(childs and childs of childs) of self for element, default is False If neither up nor down is specified, will search both directions order keyword defines in what order the path will be returned and can be set to ‘top’, ‘bottom’ or ‘self’, order by default is ‘top’ ‘top’ means path will be returned from ancestor to descendant ‘bottom’ means path will be returned from descendant to ancestor ‘self’ means path will be returned from self to element
postorder()
Postorder traversal of a tree.
preorder()
The standard preorder traversal iterator.
root()
Root node of self, if self is a subtree, will travel up to top most node of containing tree
size()
Returns the number of elements (nodes) in the tree.
top(index=0)
The nth top node of self (by default first)
tops()
Iterator on the top nodes of self, the subtrees that have no parent in self, will yield only self if self isn’t a forest
view()
Shortcut for print(self.formatted())
class MetaTree.IndexedPyTree

Additionnal methods for pure python indexed trees implementation, elements must have unique values or Tree class must define a key method that provides a unique key for each element

elementKey(element)
get(value, default=())
Identical to the __getitem__ method but will return a default value instead of raising KeyError if nor result is found
class MetaTree.MuTree

Additionnal methods for a Mutable Tree class.

graft(element, parent=None, next=None)
Attach element to self. If parent is secified, will be grafted as last child of parent (or before child ‘next’), if parent is not in self, will raise an exception, if parent is None will be grafted at top level of self, besides any existing root(s). If next is specified, self will be grafted before next in the list of parent’s childs, if next is not in parent’s childs, will raise an exception, if next is None, self will be grafted as last child under parent.
pop(element)
Delete top node of self and reparent all it’s subtrees under it’s current parent. If self was a root all it’s subtrees become separate trees of a forest under the ‘None’ root. self will now have the new parent as top node
prune(element)
Ungrafts element from self, with everything under it
reroot(element)
Reroot self so that element is self new top node
class MetaTree.NxTree
Core methods for trees based on the networkx library, these trees are indexed by implementation (name of an element must be unique)
class MetaTree.PyTree(*args, **kwargs)

Core methods for pure python trees implementation

add(element, parent=None, next=None)
Add an element to self. parent and next element can be specified. Element will be added as a child of parent, parent can be any element or subtree of self: if parent is specified as a value there must exactly one match in self or an exception will be raised if parent is None, element will be added as a sibling of self’s top node(s) if next is not none, element will be added before next in the childs of parent, else as a last childs
childs()
Returns an iterator on all childs of self, or an empty iterator if self has no childs
get(value, default=())
Identical to the __getitem__ method but will return a default value instead of raising KeyError if nor result is found
hasChilds()
isElement()
issubtree(other)
remove(element)
Remove element from self, along with everything under it, will raise an exception if element is not in self
siblings()
Returns an iterator on self siblings, not including self and starting with self next sibling, if self has no siblings (self has no parent or is unique child) then returns an empty iterator
sort(*args)
MetaTree.TreeType
The type used for internal tree storage for that tree class.

Previous topic

pymel.util.trees.MappingView

Next topic

pymel.util.trees.MutableMapping

Core

Core Modules

Other Modules

This Page