def _buildPluginHierarchy(dummyClasses=None): '''Dynamically query the mel node hierarchy for all plugin node types This command must be run from within a running maya session - ie, where maya.cmds, etc are accessible. ''' import pymel.internal.apicache as apicache if dummyClasses is None: dummyClasses = _createDummyPluginNodeClasses() # note that we always try to query inheritance, even for node types in # NON_CREATABLE, because post 2012, we should be able to query inheritance # without needing to create a node... inheritances = {} for pluginType, dummyClass in dummyClasses.iteritems(): nodeType = dummyClass.mayaName() wasRegistered = dummyClass.isRegistered() if not wasRegistered: dummyClass.register() try: try: inheritance = apicache.getInheritance(nodeType) except apicache.ManipNodeTypeError: continue finally: if not wasRegistered: dummyClass.deregister() if not inheritance: # If there was a problem creating a node - for instance, in the # case of MPxParticleAttributeMapperNode... continue assert inheritance[-1] == nodeType inheritances[pluginType] = inheritance[:-1] return inheritances
def _buildPluginHierarchy(dummyClasses=None): """Dynamically query the mel node hierarchy for all plugin node types This command must be run from within a running maya session - ie, where maya.cmds, etc are accessible. """ import pymel.internal.apicache as apicache if dummyClasses is None: dummyClasses = _createDummyPluginNodeClasses() # note that we always try to query inheritance, even for node types in # NON_CREATABLE, because post 2012, we should be able to query inheritance # without needing to create a node... inheritances = {} for pluginType, dummyClass in dummyClasses.iteritems(): nodeType = dummyClass.mayaName() wasRegistered = dummyClass.isRegistered() if not wasRegistered: dummyClass.register() try: try: inheritance = apicache.getInheritance(nodeType) except apicache.ManipNodeTypeError: continue finally: if not wasRegistered: dummyClass.deregister() if not inheritance: # If there was a problem creating a node - for instance, in the # case of MPxParticleAttributeMapperNode... continue assert inheritance[-1] == nodeType inheritances[pluginType] = inheritance[:-1] return inheritances
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()]