Exemple #1
0
def _getNodeHierarchy( version=None ):
    """
    get node hierarchy as a list of 3-value tuples:
        ( nodeType, parents, children )
    """
    import pymel.util.trees as trees
    
    if versions.current() >= versions.v2012:
        # We now have nodeType(isTypeName)! yay!

        # For whatever reason, we can't query these objects from the hierarchy
        # correctly using nodeType(isTypeName)
        inheritances = {'file':[u'texture2d', u'file']}
        
        
        for nodeType in cmds.allNodeTypes():
            inheritance = cmds.nodeType(nodeType, inherited=True,
                                        isTypeName=True)
            if inheritance is None:
                if nodeType in inheritances:
                    pass
                else:
                    raise RuntimeError("Could not query the inheritance of node type %s" % nodeType)
            else:
                inheritances[nodeType] = inheritance
        
        parentTree = {}
        # Convert inheritance lists node=>parent dict
        for nodeType, inheritance in inheritances.iteritems():
            assert inheritance[-1] == nodeType
            for i in xrange(len(inheritance)):
                child = inheritance[i]
                if i == 0:
                    if child == 'dependNode':
                        continue
                    else:
                        parent = 'dependNode'
                else:
                    parent = inheritance[i - 1]
                
                if child in parentTree:
                    assert parentTree[child] == parent
                else:
                    parentTree[child] = parent
        nodeHierarchyTree = trees.treeFromDict(parentTree)
    else:
        from parsers import NodeHierarchyDocParser
        parser = NodeHierarchyDocParser(version)
        nodeHierarchyTree = trees.IndexedTree(parser.parse())
    return [ (x.value, tuple( [y.value for y in x.parents()]), tuple( [y.value for y in x.childs()] ) ) \
             for x in nodeHierarchyTree.preorder() ]
Exemple #2
0
def _getNodeHierarchy(version=None):
    """
    get node hierarchy as a list of 3-value tuples:
        ( nodeType, parents, children )
    """
    import pymel.util.trees as trees
    import pymel.internal.apicache as apicache

    if versions.current() >= versions.v2012:
        # We now have nodeType(isTypeName)! yay!
        inheritances = {}
        for nodeType in apicache._getAllMayaTypes():
            try:
                inheritances[nodeType] = apicache.getInheritance(nodeType)
            except apicache.ManipNodeTypeError:
                continue
            except Exception:
                print "Error getting inheritance: %s" % nodeType
                raise

        parentTree = {}
        # Convert inheritance lists node=>parent dict
        for nodeType, inheritance in inheritances.iteritems():
            for i in xrange(len(inheritance)):
                child = inheritance[i]
                if i == 0:
                    if child == 'dependNode':
                        continue
                    else:
                        parent = 'dependNode'
                else:
                    parent = inheritance[i - 1]

                if child in parentTree:
                    assert parentTree[child] == parent, "conflicting parents: node type '%s' previously determined parent was '%s'. now '%s'" % (child, parentTree[child], parent)
                else:
                    parentTree[child] = parent
        nodeHierarchyTree = trees.treeFromDict(parentTree)
    else:
        from .parsers import NodeHierarchyDocParser
        parser = NodeHierarchyDocParser(version)
        nodeHierarchyTree = trees.IndexedTree(parser.parse())
    return [(x.value, tuple(y.value for y in x.parents()), tuple(y.value for y in x.childs()))
            for x in nodeHierarchyTree.preorder()]
Exemple #3
0
    commonMayaAncestorToApiTypes.setdefault(mayaType, []).append(apiType)

# now, get a list of maya types for which there is only ONE api type that has
# it as it's most-specific-common-ancestor...
commonMayaAncestorToSingleApi = {}
for mayaType, apiTypes in commonMayaAncestorToApiTypes.iteritems():
    if len(apiTypes) == 1:
        commonMayaAncestorToSingleApi[mayaType] = apiTypes[0]

# these are api types which are shared by all dependency nodes
baseApiTypes = set(['kBase', 'kNamedObject', 'kDependencyNode'])

parentDict = dict((mayaType, parents[0])
                  for mayaType, (parents, children) in nodeTypeTree.iteritems()
                  if parents)
nodeTreeObj =  trees.treeFromDict(parentDict)
#orderedTree = [ (x.value, tuple(y.value for y in x.parents()), tuple(y.value for y in x.childs()) ) \
#                for x in nodeTreeObj.preorder() ]

guessedByCommonAncestor = {}
guessedByName = {}
nameAncestorConflicts = {}
guessedByUnique = {}
multiplePossibilities = {}
noUnique = {}

noChildIntersection = set()
childIntersections = {}
childUnions = {}
parentUnions = {}
childPreorders = {}
Exemple #4
0
    commonMayaAncestorToApiTypes.setdefault(mayaType, []).append(apiType)

# now, get a list of maya types for which there is only ONE api type that has
# it as it's most-specific-common-ancestor...
commonMayaAncestorToSingleApi = {}
for mayaType, apiTypes in commonMayaAncestorToApiTypes.items():
    if len(apiTypes) == 1:
        commonMayaAncestorToSingleApi[mayaType] = apiTypes[0]

# these are api types which are shared by all dependency nodes
baseApiTypes = set(['kBase', 'kNamedObject', 'kDependencyNode'])

parentDict = dict((mayaType, parents[0])
                  for mayaType, (parents, children) in nodeTypeTree.items()
                  if parents)
nodeTreeObj =  trees.treeFromDict(parentDict)
#orderedTree = [ (x.value, tuple(y.value for y in x.parents()), tuple(y.value for y in x.childs()) ) \
#                for x in nodeTreeObj.preorder() ]

guessedByCommonAncestor = {}
guessedByName = {}
nameAncestorConflicts = {}
guessedByUnique = {}
multiplePossibilities = {}
noUnique = {}

noChildIntersection = set()
childIntersections = {}
childUnions = {}
parentUnions = {}
childPreorders = {}