예제 #1
0
 def iterChildren(self, fnFilters=None, includeMeta=False):
     filterTypes = fnFilters or ()
     for source, destinations in nodes.iterConnections(self.mobject(), True, False):
         destNode = destinations.node()
         if not filterTypes or any(destNode.hasFn(i) for i in filterTypes):
             if not includeMeta and isMetaNode(destNode):
                 continue
             yield destNode
예제 #2
0
 def iterConnections(self, source=True, destination=True):
     """
     :param source: if True then return all nodes downstream of the node
     :type source: bool
     :param destination: if True then return all nodes upstream of this node
     :type destination: bool
     :return:
     :rtype: generator
     """
     return nodes.iterConnections(self.mobject(), source, destination)
예제 #3
0
def isConnectedToMeta(node):
    """Determines if the node is directly connected to a meta node by searching upstream of the node

    :param node: om2.MObject
    :rtype: bool
    """
    for dest, source in nodes.iterConnections(node, True, False):
        if isMetaNode(source.node()):
            return True
    return False
예제 #4
0
def getUpstreamMetaNodeFromNode(node):
    """Returns the upstream meta node from node expecting the node to have the metaNode attribute

    :param node: the api node to search from
    :type node: om2.MObject
    :rtype: MetaBase
    """
    for dest, source in nodes.iterConnections(node, False, True):
        node = source.node()
        if isMetaNode(node):
            return dest, MetaBase(node)
    return None, None
예제 #5
0
 def allChildrenNodes(self, recursive=False, includeMeta=False):
     children = []
     for source, destination in nodes.iterConnections(self.mobject(), True, False):
         node = destination.node()
         if node not in children:
             if includeMeta and om2.MFnDependencyNode(node).hasAttribute("isHive"):
                 continue
             children.append(destination.node())
     if recursive:
         for child in self.iterMetaChildren():
             children.extend([i for i in child.allChildrenNodes() if i not in children])
     return children
예제 #6
0
def getConnectedMetaNodes(mObj):
    """Returns all the downStream connected meta nodes of 'mObj'

    :param mObj: The meta node MObject to search
    :type mObj: om2.MObject
    :return: A list of MetaBase instances, each node will have its own subclass of metabase returned.
    :rtype: list(MetaBase)
    """
    mNodes = []
    for dest, source in nodes.iterConnections(mObj, False, True):
        node = source.node()
        if isMetaNode(node):
            mNodes.append(MetaBase(node))
    return mNodes
예제 #7
0
def getConnectedMetaNodes(mObj, direction=om2.MItDependencyGraph.kDownstream):
    """Returns all the downStream connected meta nodes of 'mObj'

    :param mObj: The meta node MObject to search
    :type mObj: om2.MObject
    :return: A list of MetaBase instances, each node will have its own subclass of metabase returned.
    :rtype: list(MetaBase)
    """
    mNodes = []
    useSource = direction == om2.MItDependencyGraph.kDownstream
    usedestination = direction == om2.MItDependencyGraph.kUpstream
    for dest, endPoint in nodes.iterConnections(mObj, useSource, usedestination):
        node = endPoint.node()
        if isMetaNode(node):
            mNodes.append(MetaBase(node))
    return mNodes
예제 #8
0
 def iterMetaTree(self, depthLimit=256):
     """This function traverses the meta tree pulling out any meta node this is done by checking each node 
     has the mclass Attribute. This function can be slow depending on the size of the tree 
     
     :param depthLimit: 
     :type depthLimit: int
     :rtype: generator(MetaBase)
     """
     if depthLimit < 1:
         return
     for source, destination in nodes.iterConnections(self.mobject(), False, True):
         node = destination.node()
         if isMetaNode(node):
             m = MetaBase(node)
             yield m
             for i in m.iterMetaTree(depthLimit=depthLimit - 1):
                 yield i
예제 #9
0
def findConstraint(node, kType, includeReferenced=True):
    """Searches the upstream graph one level  in search for the corresponding kConstraintType

    :param node: The node to search upstream from
    :type node: om2.MObject
    :param kType: The maya MFn.kConstraintType eg. om2.MFn.kParentConstraint
    :type kType: om2.MFn.kConstraintType
    :param includeReferenced: If True will return the constraint regardless of whether the node is referenced /
    If False then only non-referenced constraints would be returned
    :type includeReferenced: bool
    :return: The MObject representing the constraint
    :rtype: om2.MObject or None
    """
    for source, destination in nodes.iterConnections(node, source=False, destination=True):
        dest = destination.node()
        if dest.apiType() == kType and (includeReferenced or not om2.MFnDependencyNode(dest).isFromReferencedFile):
            return dest
예제 #10
0
    def disconnectFromNode(self, node):
        """

        :param node: The destination node to disconnect from this meta node
        :type node: om2.MObject
        :return: success value
        :rtype: bool
        """
        metaObj = self.mobject()
        for source, destination in nodes.iterConnections(node, False, True):
            if source.node() != metaObj:
                continue
            plugs.disconnectPlug(source, destination)
            if source.isLocked:
                source.isLocked = False
            cmds.deleteAttr(destination.name())
            self.removeAttribute(source.name())
            return True
        return False
예제 #11
0
def isConnectedToMeta(node):
    for dest, source in nodes.iterConnections(node, True, False):
        if isMetaNode(source.node()):
            return True
    return False