Ejemplo n.º 1
0
def contain(type):
    selection = pymel.ls(selection=True)
    if type == 'dag':
        type = 'dagContainer'


    positions = {}
    for each in selection:
        positions[each] = pymel.hyperGraph(HYPER_GRAPH, query=True, getNodePosition=selection[0])

    container = pymel.container(type=type, includeHierarchyBelow=True, )
    pymel.container(addNode=selection, edit=True, includeHierarchyBelow=True, force=True)
    print container
    pymel.select( cl=True )

    #pymel.evalDeferred('pymel.select("'+container+'", replace=True,)')
    #pymel.evalDeferred('pymel.hyperGraph("'+hyperGraph+'", edit=True, expandContainer=True)')



    def deferredCauseMayaIsStupid():
        pymel.select(container, replace=True,)
        pymel.hyperGraph(HYPER_GRAPH, edit=True, expandContainer=True)

        for each in positions:
            pymel.hyperGraph(HYPER_GRAPH, edit=True, setNodePosition=[each, positions[each][0], positions[each][1]])

        posX, posY = pymel.hyperGraph(HYPER_GRAPH, query=True, getNodePosition=container)
        pymel.hyperGraph(HYPER_GRAPH, edit=True, setNodePosition=[each, posX, posY+3])


    pymel.evalDeferred( deferredCauseMayaIsStupid)
Ejemplo n.º 2
0
def isolateInGraph():
    selection = pymel.ls(selection=True)
    positions = {}

    for each in selection:
        positions[each] = pymel.hyperGraph(HYPER_GRAPH, query=True, getNodePosition=each)

    mel.eval('hyperShadePanelGraphCommand("hyperShadePanel1",  "clearGraph")')

    OOOOOOO = 'positions';  print '%s = %s %s'%(str(OOOOOOO),str(eval(OOOOOOO)),str(type(eval(OOOOOOO))))
    for each in selection:
        pymel.select(each)
        #mel.eval("ka_hgAdd")
        print each
        pymel.hyperGraph(HYPER_GRAPH, edit=True, addDependNode=each)
        pymel.hyperGraph(HYPER_GRAPH, edit=True, setNodePosition=[each, positions[each][0], positions[each][1]])

    pymel.select(selection)
Ejemplo n.º 3
0
    def deferredCauseMayaIsStupid():
        pymel.select(container, replace=True,)
        pymel.hyperGraph(HYPER_GRAPH, edit=True, expandContainer=True)

        for each in positions:
            pymel.hyperGraph(HYPER_GRAPH, edit=True, setNodePosition=[each, positions[each][0], positions[each][1]])

        posX, posY = pymel.hyperGraph(HYPER_GRAPH, query=True, getNodePosition=container)
        pymel.hyperGraph(HYPER_GRAPH, edit=True, setNodePosition=[each, posX, posY+3])
Ejemplo n.º 4
0
    def getHypershade_nodeUnderMouse(self):
        """Returns the node under the mouse in the hypershade tool context"""
        if self._hypershade_NodeUnderMouse != None:
            return self._hypershade_NodeUnderMouse

        hypergraph = "graph1HyperShadeEd"
        nodeUnderMouse = pymel.hyperGraph(
            hypergraph,
            query=True,
            feedbackNode=True,
        )

        if nodeUnderMouse:
            self._hypershade_NodeUnderMouse = pymel.ls(nodeUnderMouse)[
                0]  #return pymel object

        return self._hypershade_NodeUnderMouse
Ejemplo n.º 5
0
def purgeGraphOfContainers():
    hyperGraph = 'graph1HyperShadeEd'

    nodesInGraph = pymel.hyperGraph(HYPER_GRAPH, query=True, getNodeList=True)
    nodePositionDict = {}
    for node in nodesInGraph:
        node = pymel.ls(node)[0]
        if node.nodeType() != 'dagContainer':
            x, y = pymel.hyperGraph(HYPER_GRAPH, getNodePosition=node, query=True, )
            nodePositionDict[node] = (x, y)

    clear()
    for node in nodePositionDict:
        x,y = nodePositionDict[node]
        pymel.hyperGraph(HYPER_GRAPH, edit=True, addDependNode=node,)
        #pymel.select(node)
        #pymel.select(node)
        #add()
        #pymel.hyperGraph('hyperShadePanel1', edit=True, setNodePosition=[node, x, y])
        pymel.hyperGraph(HYPER_GRAPH, edit=True, setNodePosition=[node, x, y])
Ejemplo n.º 6
0
def alignNodes(alignment):
    selection = pymel.ls(selection=True)
    hyperGraph = 'graph1HyperShadeEd'

    if len(selection) >= 2:

        posX, posY = pymel.hyperGraph(HYPER_GRAPH, query=True, getNodePosition=selection[0])

        for each in selection[1:]:

            container = pymel.container(query=True, findContainer=[each])
            if container:
                pymel.setAttr(container+'.blackBox', 0)

            if alignment == 'horizontal':
                posX += 200
            elif alignment == 'vertical':
                posY -= 200
            else:
                print 'ERROR, no alignment set'

            pymel.hyperGraph(HYPER_GRAPH, edit=True, addDependNode=each)
            pymel.hyperGraph(HYPER_GRAPH, edit=True, setNodePosition=[each, posX, posY])
            print pymel.hyperGraph(HYPER_GRAPH, query=True, look=True)
Ejemplo n.º 7
0
def graphInputOutput(mode='all', depthLimit=4):

    selection = pymel.ls(selection=True)
    hyperGraph = 'graph1HyperShadeEd'
    nodeDict = {}

    dataDict = {'maxNodeLimit':ka_preference.get('hyperGraph_maxGraphSize', 100),
                'numberOfNodes':0,
                'nodesToAdd':{}, # dict is for fast uniqueness checking
                'orderedNodesToAdd':[],
                'nodeCount':0,
                'totalNodeCount':0,
                'nodeLimitExeeded':False,
                'stopGraphing':False,
                }

    addList = []
    addList.extend(selection)


    def addNodesToGraphList(nodes, dataDict):
        if not dataDict['stopGraphing']:
            if not isinstance(nodes, list):
                nodes = [nodes]

            # add to data
            uniqueInputs = 0
            for node in nodes:
                if node not in dataDict['nodesToAdd']:
                    if node.nodeType() not in ['hyperLayout', 'dagContainer', 'container']:
                        dataDict['nodesToAdd'][node] = True
                        dataDict['orderedNodesToAdd'].append(node)
                        dataDict['nodeCount'] += 1
                        dataDict['totalNodeCount'] += 1


                        # check if over max
                        if dataDict['nodeCount'] >= dataDict['maxNodeLimit']:

                            if dataDict['nodeLimitExeeded']:
                                message = 'You are about to graph an additional %s items (%s total).\n This could be slow, do you want to continue?' % (str(dataDict['nodeCount']), str(dataDict['totalNodeCount']))
                            else:
                                message = 'You are about to graph %s items.\n This could be slow, do you want to continue?' % str(dataDict['nodeCount'])


                            result = cmds.confirmDialog( title='Large Graph Operation', message=message, button=['Continue', 'Stop and Graph', 'Cancel'], defaultButton='Yes', cancelButton='Cancel', dismissString='Cancel' )
                            if result == 'Stop and Graph':
                                dataDict['stopGraphing'] = True
                                dataDict['nodeLimitExeeded'] = True
                                break

                            elif result == 'Cancel':
                                pymel.error('graphing aborted by user...')

                            else:
                                dataDict['nodeCount'] = 0
                                dataDict['nodeLimitExeeded'] = True

        return dataDict


    # add selection
    dataDict = addNodesToGraphList(selection, dataDict)



    if mode == 'inputs' or mode == 'all':
        inputDepth = []
        inputDepth.append(selection)

        while len(inputDepth) < depthLimit:
            newDepth = []

            for each in inputDepth[-1]:
                inputs = pymel.listConnections( each, destination=False, source=True, skipConversionNodes=False)

                if inputs:
                    newDepth.extend(inputs)
                    dataDict = addNodesToGraphList(inputs, dataDict)
                    if dataDict['stopGraphing']:
                        break
                        break

                #if inputs:
                    #uniqueInputs = 0
                    #for eachInput in inputs:
                        #if eachInput not in nodeDict:
                            #nodeDict[eachInput.__hash__()] = True
                            #uniqueInputs += 1
                            #newDepth.append(eachInput)

                    #if uniqueInputs:
                        #numberOfNodes = addToMaxLimit(uniqueInputs, numberOfNodes)


            inputDepth.append(newDepth)

        #numberOfNodes = addToMaxLimit(len(inputDepth[-1]), numberOfNodes)
        dataDict = addNodesToGraphList(inputDepth[-1], dataDict)

        #for inputList in inputDepth:
            #for each in inputList:
                #if not each in addList and pymel.nodeType(each) != 'hyperLayout':
                    #addList.append(each)



    if mode == 'outputs' or mode == 'all':
        outputDepth = []
        outputDepth.append(selection)

        while len(outputDepth) < depthLimit:
            newDepth = []

            for each in outputDepth[-1]:
                outputs = pymel.listConnections( each, destination=True, source=False, skipConversionNodes=False)
                if outputs:
                    newDepth.extend(outputs)
                    dataDict = addNodesToGraphList(outputs, dataDict)
                    if dataDict['stopGraphing']:
                        break
                        break

            outputDepth.append(newDepth)

        #numberOfNodes = addToMaxLimit(len(outputDepth[-1]), numberOfNodes)
        dataDict = addNodesToGraphList(outputDepth[-1], dataDict)

        #for outputList in outputDepth:
            #for each in outputList:
                #if not each in addList and pymel.nodeType(each) != 'hyperLayout':
                    #addList.append(each)


    pymel.hyperGraph(HYPER_GRAPH, edit=True, clear=True)
    unblackBoxList = []

    for node in dataDict['orderedNodesToAdd']:

        container = getContainerOfNode(node)

        if container:
            if isinstance(container, list):
                container = container[0]

            if not container in unblackBoxList:
                if container.blackBox.get():
                    unblackBoxList.append(container)

    for container in unblackBoxList:
        pymel.setAttr(container+'.blackBox', 0)

    for node in dataDict['orderedNodesToAdd']:

        #if not pymel.nodeType(node) in ['dagContainer', 'container']:
        pymel.hyperGraph(HYPER_GRAPH, edit=True, setNodePosition=[node, 0, 0])


    pymel.evalDeferred('mel.eval(\'hyperShadePanelGraphCommand("hyperShadePanel1", "rearrangeGraph");\')')

    pymel.evalDeferred('import pymel.core as pymel')
    pymel.evalDeferred('pymel.hyperGraph(\'graph1HyperShadeEd\', edit=True, frameGraph=True)')
    pymel.evalDeferred('pymel.hyperGraph(\'graph1HyperShadeEd\', edit=True, frameGraph=True)')
    pymel.evalDeferred('pymel.hyperGraph(\'graph1HyperShadeEd\', edit=True, frameGraph=True)')
    pymel.evalDeferred('pymel.hyperGraph(\'graph1HyperShadeEd\', edit=True, frameGraph=True)')

    for container in unblackBoxList:
        pymel.setAttr(container+'.blackBox', 1)
Ejemplo n.º 8
0
def add():
    #mel.eval("ka_hgAdd")
    pymel.hyperGraph(HYPER_GRAPH, edit=True, addDependNode=each)
Ejemplo n.º 9
0
def clear():
    #mel.eval('hyperShadePanelGraphCommand("hyperShadePanel1",  "clearGraph")')
    pymel.hyperGraph(HYPER_GRAPH, edit=True, clear=True)