Package mrv :: Package maya :: Package nt :: Module base :: Class DagNode
[hide private]
[frames] | no frames]

Class DagNode

source code

             object --+                
                      |                
                   Node --+            
                          |            
         object --+       |            
                  |       |            
interface.Interface --+   |            
                      |   |            
interface.iDuplicatable --+            
                          |            
                 DependNode --+        
                              |        
                  ContainerBase --+    
                                  |    
                             Entity --+
                                      |
                     object --+       |
                              |       |
            interface.Interface --+   |
                                  |   |
                 interface.iDagItem --+
                                      |
                                     DagNode

Implements access to DAG nodes
Instance Methods [hide private]
 
__getitem__(self, index)
Returns: if index >= 0: Node(child) at index
source code
 
name(self)
Returns: fully qualified (long) name of this dag node
source code
 
_dagPath_delayed(self)
Handles the retrieval of a dagpath from an MObject if it is not known at first.
source code
 
_dagPath_cached(self)
Returns: MDagPath attached to this node from a cached location
source code
 
_object_cached(self)
Returns: MObject associated with the path of this instance from a cached location
source code
 
_object_delayed(self)
Returns: MObject as retrieved from the MDagPath of our Node
source code
 
dagPath(self)
Returns: the original DagPath attached to this Node - it's not wrapped for performance
source code

Inherited from DependNode: setLocked

Inherited from Node: __hash_2009__, __new__

Inherited from interface.iDuplicatable: copyTo, copyToOther

Inherited from interface.Interface: supports

Inherited from object: __delattr__, __format__, __getattribute__, __init__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

    DAG Modification
 
_setWorldspaceTransform(self, parentnode)
Set ourselve's transformation matrix to our absolute worldspace transformation, possibly relative to the optional parentnode
source code
 
reparent(self, parentnode, renameOnClash=True, raiseOnInstance=True, keepWorldSpace=False)
Change the parent of all nodes (also instances) to be located below parentnode
source code
 
unparent(self, **kwargs)
As reparent, but will unparent this transform under the scene root
source code
 
addInstancedChild(self, childNode, position=MFnDagNode.kNextPos)
Add childnode as instanced child to this node
source code
 
removeChild(self, childNode, allowZeroParents=False)
remove the given childNode (being a child of this node) from our child list, effectively parenting it under world !
source code
 
addChild(self, childNode, position=MFnDagNode.kNextPos, keepExistingParent=False, renameOnClash=True, keepWorldSpace=False)
Add the given childNode as child to this Node.
source code
 
addParent(self, parentnode, **kwargs)
Adds ourselves as instance to the given parentnode at position
source code
 
setParent(self, parentnode, **kwargs)
Change the parent of self to parentnode being placed at position
source code
 
removeParent(self, parentnode)
Remove ourselves from given parentnode
source code
    Edit
 
delete(self)
Delete this node - this special version must be
source code
 
duplicate(self, newpath='', autocreateNamespace=True, renameOnClash=True, newTransform=False, **kwargs)
Duplciate the given node to newpath
source code

Inherited from DependNode: addAttribute, removeAttribute, rename, setNamespace

Inherited from DependNode (private): _addRemoveAttr

    DAG Status Information
 
_checkHierarchyVal(self, plugName, cmpval)
Returns: cmpval if the plug value of one of the parents equals cmpval as well as the current entity
source code
 
_getDisplayOverrideValue(self, plugName)
Returns: the given effective display override value or None if display overrides are disabled
source code
 
isVisible(self)
Returns: True if this node is visible - its visible if itself and all parents are visible
source code
 
isTemplate(self)
Returns: True if this node is templated - this is the case if itself or one of its parents are templated
source code
 
displayOverrideValue(self, plugName)
Returns: the override display value actually identified by plugName affecting the given object (that should be a leaf node for the result you see in the viewport.
source code
    DAG Query
 
parentAtIndex(self, index)
Returns: Node of the parent at the given index - non-instanced nodes only have one parent
source code
 
transform(self)
Returns: Node to lowest transform in the path attached to our node
source code
 
parent(self)
Returns: Maya node of the parent of this instance or None if this is the root
source code
 
children(self, predicate=lambda x: True, asNode=True)
Returns: all child nodes below this dag node if predicate returns True for passed Node
source code
 
childrenByType(self, nodeType, predicate=lambda x: True)
Returns: all childnodes below this one matching the given nodeType and the predicate
source code
 
shapes(self, predicate=lambda x: True)
Returns: all our Shape nodes
source code
 
childTransforms(self, predicate=lambda x: True)
Returns: list of all transform nodes below this one
source code
 
instanceNumber(self)
Returns: our instance number
source code
 
instance(self, instanceNumber)
Returns: Node to the instance identified by instanceNumber
source code
 
hasChild(self, node)
Returns: True if node is a child of self
source code
 
child(self, index)
Returns: child of self at index
source code
    Iterators
 
iterInstances(self, excludeSelf=False)
Get iterator over all (direct and indirect)instances of this node
source code

Inherited from interface.iDagItem: iterParents

    Overridden Methods
 
__eq__(self, other)
Compare MDagPaths directly Valid inputs are Node, DagNode, MObject and MDagPath instances.
source code
 
__ne__(self, other) source code

Inherited from DependNode: __getattr__, __repr__, __str__

Inherited from Node: __hash__

    Sets Handling
 
_getSetPlug(self)
Returns: the iogplug properly initialized for self Dag Nodes have the iog plug as they support instancing
source code

Inherited from DependNode: addTo, connectedSets, isMemberOf, removeFrom, sets

    Connections and Attributes

Inherited from DependNode: connections, dependencyInfo

    Status
 
isValid(self)
Returns: True if the object exists in the scene
source code

Inherited from DependNode: isAlive

    General Query
 
basename(self)
Returns: basename of this path, '/hello/world' -> 'world'
source code
 
object(self)
Returns: MObject as retrieved from the MDagPath of our Node
source code
 
apiObject(self)
Returns: our dag path as this is our api object - the object defining this node best
source code

Inherited from DependNode: referenceFile

    Interface

Inherited from Node: apiType, hasFn

Inherited from interface.iDuplicatable: copyFrom, createInstance

    Query Methods

Inherited from interface.iDagItem: childrenDeep, isPartOf, isRoot, isRootOf, parentDeep, root

    Name Generation

Inherited from interface.iDagItem: fullChildName

Class Methods [hide private]
    Interface

Inherited from Node: getMFnClasses

    Name Generation

Inherited from interface.iDagItem: addSep

Class Variables [hide private]
  kNextPos = MFnDagNode.kNextPos

Inherited from Node: __metaclass__

Inherited from interface.iDagItem: kOrder_BreadthFirst, kOrder_DepthFirst

    preset type filters

Inherited from DependNode: fSets, fSetsObject

    Configuration
  _sep = "|"
hash(x)
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__eq__(self, other)
(Equality operator)

source code 
Compare MDagPaths directly Valid inputs are Node, DagNode, MObject and MDagPath instances.
Overrides: Node.__eq__

__ne__(self, other)

source code 
Overrides: Node.__ne__

__getitem__(self, index)
(Indexing operator)

source code 
Returns:

if index >= 0: Node(child) at index

  • if index < 0: Node parent at -(index+1)(if walking up the hierarchy)
  • If index is string, use DependNodes implementation

Note: returned child can be transform or shape, use shapes or childTransforms if you need a quickfilter

_getSetPlug(self)

source code 
Returns:
the iogplug properly initialized for self Dag Nodes have the iog plug as they support instancing
Overrides: DependNode._getSetPlug

_setWorldspaceTransform(self, parentnode)

source code 
Set ourselve's transformation matrix to our absolute worldspace transformation, possibly relative to the optional parentnode
Parameters:
  • parentnode - if not None, it is assumed to be the future parent of the node, our transformation will be set such that we retain our worldspace position if parented below parentnode

reparent(self, parentnode, renameOnClash=True, raiseOnInstance=True, keepWorldSpace=False)

source code 

Change the parent of all nodes (also instances) to be located below parentnode

:return : copy of self pointing to the new dag path self

Parameters:
  • parentnode - Node instance of transform under which this node should be parented to if None, node will be reparented under the root (which only works for transforms)
  • renameOnClash - resolve nameclashes by automatically renaming the node to make it unique
  • raiseOnInstance - if True, this method will raise if you try to reparent an instanced object. If false, instanced objects will be merged into the newly created path under parentnode, effectively eliminating all other paths , keeping the newly created one
  • keepWorldSpace - if True and node to be reparented is a transform, the world space position will be kept by adjusting the transformation accordingly. WARNNG: Currently we reset pivots when doing so
Decorators:
  • @undoable
Notes:
  • will remove all instance of this object and leave this object at only one path - if this is not what you want, use the addChild method instead as it can properly handle this case
  • this method handles namespaces properly

unparent(self, **kwargs)

source code 
As reparent, but will unparent this transform under the scene root
Decorators:
  • @undoable

addInstancedChild(self, childNode, position=MFnDagNode.kNextPos)

source code 
Add childnode as instanced child to this node
Decorators:
  • @undoable
Notes:
  • for more information, see addChild
  • its a shortcut to addChild allowing to clearly indicate what is happening

removeChild(self, childNode, allowZeroParents=False)

source code 
remove the given childNode (being a child of this node) from our child list, effectively parenting it under world !
Parameters:
  • childNode - Node to unparent - if it is not one of our children, no change takes place
  • allowZeroParents - if True, it is possible to leave a node unparented, thus no valid dag paths leads to it. If False, transforms will just be reparented under the world
Returns:
copy of childnode pointing to the first valid dag path we find.
Decorators:
  • @undoable
Notes:
  • to prevent the child (if transform) to dangle in unknown space if the last instance is to be removed, it will instead be reparented to world.
  • removing shapes from their last parent will result in an error

addChild(self, childNode, position=MFnDagNode.kNextPos, keepExistingParent=False, renameOnClash=True, keepWorldSpace=False)

source code 
Add the given childNode as child to this Node. Allows instancing !
Parameters:
  • childNode - Node you wish to add
  • position - the index to which to add the new child, kNextPos will add it as last child. It supports python style negative indices
  • keepExistingParent - if True, the childNode will be instanced as it will have its previous parent(s) and this one, if False, the previous parent will be removed from the child's parent list
  • renameOnClash - resolve nameclashes by automatically renaming the node to make it unique
  • keepWorldSpace - see reparent, only effective if the node is not instanced
Returns:
childNode whose path is pointing to the new child location
Decorators:
  • @undoable
Raises:
  • ValueError - if keepWorldSpace is requested with directly instanced nodes
Notes:
  • as maya internally handles add/remove child as instancing operation, even though keepExistingParent is False, it will mess up things and for a short period of time in fact have two n + 1 instances, right before one is unlinked, This still fills a slot or something, and isInstanced will be true, although the pathcount is 1. Long story short: if the item to be added to us is not instanced, we use reparent instead. It will not harm in direct instances, so its save to use.
  • if the instance count of the item is 1 and keepExistingParent is False, the position argument is being ignored

addParent(self, parentnode, **kwargs)

source code 
Adds ourselves as instance to the given parentnode at position
Parameters:
Returns:
self with updated dag path
Decorators:
  • @undoable

setParent(self, parentnode, **kwargs)

source code 
Change the parent of self to parentnode being placed at position
Parameters:
Returns:
self with updated dag path
Decorators:
  • @undoable

removeParent(self, parentnode)

source code 
Remove ourselves from given parentnode
Returns:
None
Decorators:
  • @undoable

delete(self)

source code 
Delete this node - this special version must be
Decorators:
  • @undoable
Overrides: DependNode.delete
Notes:
  • if the undo queue is enabled, the object becomes invalid, but stays alive until it drops off the queue
  • if you want to delete many nodes, its more efficient to delete them using the global delete method

duplicate(self, newpath='', autocreateNamespace=True, renameOnClash=True, newTransform=False, **kwargs)

source code 
Duplciate the given node to newpath
Parameters:
  • newpath - result depends on its format:

    • '' - empty string, creates a unique name based on the actual node name by appending a copy number to it, if newTransform is True, the newly created shape/transform will keep its name, but receives a new parent

    • 'newname' - relative path, the node will be duplicated not changing its current parent if newTransform is False

    • |parent|newname - absolute path, the node will be duplicated and reparented under the given path

      if newTransform is True, a new transform name will be created based on your name by appending a unique copy number

  • autocreateNamespace - if true, namespaces given in newpath will be created automatically, otherwise a RuntimeException will be thrown if a required namespace does not exist
  • renameOnClash - if true, clashing names will automatically be resolved by adjusting the name
  • newTransform - if True, a new transform will be created based on the name of the parent transform of this shape node, appending a unique copy number to it. Only has an effect for shape nodes
Returns:
newly create Node
Decorators:
  • @notundoable
Overrides: interface.iDuplicatable.duplicate
Notes:
  • duplicate performance could be improved by checking more before doing work that does not really change the scene, but adds undo operations
  • inbetween parents are always required as needed
  • instancing can be realized using the addChild function
  • If meshes have tweaks applied, the duplicate will not have these tweaks and the meshes will look mislocated. Using MEL works in that case ... (they fixed it there obviously) , but creates invalid objects
To Do:
  • add example for each version of newpath
  • Undo implementation - every undoable operation must in fact be based on strings to really work, all this is far too much - dagNode.duplicate must be undoable by itself
  • duplicate should be completely reimplemented to support all mel options and actually work with meshes and tweaks - the underlying api duplication would still be used of course, as well as connections (to sets) and so on ...

_checkHierarchyVal(self, plugName, cmpval)

source code 
Returns:
cmpval if the plug value of one of the parents equals cmpval as well as the current entity

_getDisplayOverrideValue(self, plugName)

source code 
Returns:
the given effective display override value or None if display overrides are disabled

isVisible(self)

source code 
Returns:
True if this node is visible - its visible if itself and all parents are visible

isTemplate(self)

source code 
Returns:
True if this node is templated - this is the case if itself or one of its parents are templated

displayOverrideValue(self, plugName)

source code 
Returns:
the override display value actually identified by plugName affecting the given object (that should be a leaf node for the result you see in the viewport. The display type in effect is always the last one set in the hierarchy returns None display overrides are disabled

isValid(self)

source code 
Returns:
True if the object exists in the scene
Overrides: DependNode.isValid

Note: Handles DAG objects correctly that can be instanced, in which case the MObject may be valid , but the respective dag path is not. Additionally, if the object is not parented below any object, everything appears to be valid, but the path name is empty

name(self)

source code 
Returns:
fully qualified (long) name of this dag node

basename(self)

source code 
Returns:
basename of this path, '/hello/world' -> 'world'
Overrides: interface.iDagItem.basename

parentAtIndex(self, index)

source code 
Returns:
Node of the parent at the given index - non-instanced nodes only have one parent

Note: if a node is instanced, it can have parentCount parents

To Do: Update dagpath afterwards ! Use dagpaths instead !

transform(self)

source code 
Returns:
Node to lowest transform in the path attached to our node

Note: for shapes this is the parent, for transforms the transform itself

parent(self)

source code 
Returns:
Maya node of the parent of this instance or None if this is the root
Overrides: interface.iDagItem.parent

children(self, predicate=lambda x: True, asNode=True)

source code 
Parameters:
  • asNode - if True, you will receive the children as wrapped Nodes, otherwise you get MDagPaths
Returns:
all child nodes below this dag node if predicate returns True for passed Node
Overrides: interface.iDagItem.children

childrenByType(self, nodeType, predicate=lambda x: True)

source code 
Parameters:
  • nodeType - class of the nodeTyoe, like nt.Transform
Returns:
all childnodes below this one matching the given nodeType and the predicate

shapes(self, predicate=lambda x: True)

source code 
Returns:
all our Shape nodes

Note: you could use getChildren with a predicate, but this method is more efficient as it uses dagpath functions to filter shapes

childTransforms(self, predicate=lambda x: True)

source code 
Returns:
list of all transform nodes below this one

instanceNumber(self)

source code 
Returns:
our instance number

Note: 0 does not indicate that this object is not instanced - use getInstanceCount instead

instance(self, instanceNumber)

source code 
Parameters:
  • instanceNumber - range(0, self.instanceCount()-1)
Returns:
Node to the instance identified by instanceNumber

hasChild(self, node)

source code 
Returns:
True if node is a child of self

child(self, index)

source code 
Returns:
child of self at index

Note: this method fixes the MFnDagNode.child method - it returns an MObject, which doesnt work well with instanced nodes - a dag path is required, which is what we use to aquire the object

_dagPath_cached(self)

source code 
Returns:
MDagPath attached to this node from a cached location

_object_cached(self)

source code 
Returns:
MObject associated with the path of this instance from a cached location

_object_delayed(self)

source code 
Returns:
MObject as retrieved from the MDagPath of our Node

object(self)

source code 
Returns:
MObject as retrieved from the MDagPath of our Node
Overrides: DependNode.object

dagPath(self)

source code 
Returns:
the original DagPath attached to this Node - it's not wrapped for performance

Note: If you plan to alter it, make sure you copy it using the MDagPath(node.dagPath()) construct !

apiObject(self)

source code 
Returns:
our dag path as this is our api object - the object defining this node best
Overrides: Node.apiObject

iterInstances(self, excludeSelf=False)

source code 
Get iterator over all (direct and indirect)instances of this node
Parameters:
  • excludeSelf - if True, self will not be returned, if False, it will be in the list of items

Note: Iterating instances is more efficient than querying all instances individually using instance

To Do: add flag to allow iteration of indirect instances as well