get selected node?

Hi,

Is there a way for me to get selected node in python canvas? i want to get all data from that node (for example output data array which have been calculate by KL)

Thanks!

Thụy Nguyễn
CG Artist

Comments

  • EricTEricT Administrator, Moderator, Fabric Employee Posts: 298 admin

    @anhungxadieu

    You can get access to selected nodes using the following calls within the CanvasWindow.py:
    self.dfgWidget.getDFGController().getSelectedNodesName() -> returns a list
    self.dfgWidget.getDFGController().getSelectedNodesPath() -> returns a list of Node Paths (this is probably what you want)

    As an example I added some code to the onFrameChanged() method to test the workflow:

    def onFrameChanged(self, frame):
    
        # This removes the last item in the selection list each frame change
        selNodes = self.dfgWidget.getDFGController().getSelectedNodesPath()
        if len(selNodes) > 0:
            selNodes.pop()
        self.dfgWidget.getDFGController().selectNodes(selNodes)
    

    You also have access to the DFGController in the script editor like so:

    print controller.getSelectedNodesName()
    

    Eric Thivierge
    Kraken Developer
    Kraken Rigging Framework

  • anhungxadieuanhungxadieu Posts: 107

    Thank @EricT i will check it!

    Thụy Nguyễn
    CG Artist

  • anhungxadieuanhungxadieu Posts: 107

    hi @EricT, how can i print the output value of selected nodes?

    Thụy Nguyễn
    CG Artist

  • EricTEricT Administrator, Moderator, Fabric Employee Posts: 298 admin

    You will need to find the binding of the graph then the exec of the node in the graph via Python. There are some examples here that is done in Maya but similar will be done in Canvas stand alone:
    http://forums.fabricengine.com/discussion/comment/3803/#Comment_3803

    Eric Thivierge
    Kraken Developer
    Kraken Rigging Framework

  • anhungxadieuanhungxadieu Posts: 107

    i try this, and i have an error
    `
    import json, pprint

    PORT_TYPE_MAP = {
        0: 'In',
        1: 'IO',
        2: 'Out'
    }
    
    host= binding.binding.getHost()
    opBindingID = binding.binding.getBindingID()
    opBinding = host.getBindingForID(opBindingID)
    graph  = binding.binding.getExec()
    
    nodeName = controller.getSelectedNodesName()[0].encode("UTF8")
    node = graph.getSubExec(nodeName)
    nodeDesc = json.loads(graph.getNodeDesc(nodeName))
    
    for i in xrange(node.getExecPortCount()):
        portName = node.getExecPortName(i)
        portConnectionType = PORT_TYPE_MAP[node.getExecPortType(i)]
        rtVal = opBinding.getArgValue(portName)
        portDataType = rtVal.getTypeName().getSimpleType()
    
        print("==================")
        print nodeName
        print(portName)
        print(portConnectionType)
        print(rtVal)
        print(portDataType)
    

    ==================
    Decompose_1
    exec
    IO
    <RTVal:{}>
    Execute
    Traceback (most recent call last):
    File "D:\thuy_fabricengine\FabricEngine-2.5.0-Windows-x86_64\Python\2.7\FabricEngine\Canvas\ScriptEditor.py", line 575, in exec_
    exec code in self.eval_globals
    File "", line 21, in
    File "D:\thuy_fabricengine\FabricEngine-2.5.0-Windows-x86_64\Python\2.7\FabricEngine\CAPI.py", line 3142, in getArgValue
    def getArgValue(self, *args): return _CAPI.DFGBinding_getArgValue(self, *args)
    Exception: Fabric: getArgValue(name): getArgValue(name): no arg named 'this'
    `

    Thụy Nguyễn
    CG Artist

  • anhungxadieuanhungxadieu Posts: 107

    I got it!

    import json, pprint
    
    PORT_TYPE_MAP = {
        0: 'In',
        1: 'IO',
        2: 'Out'
    }
    
    host= binding.binding.getHost()
    opBindingID = binding.binding.getBindingID()
    opBinding = host.getBindingForID(opBindingID)
    graph  = binding.binding.getExec()
    
    nodeName = controller.getSelectedNodesName()[0].encode("UTF8")
    node = graph.getSubExec(nodeName)
    nodeBind = node.bind()
    nodeBind_ = nodeBind.getHost().getBindingForID(nodeBind.getBindingID())
    
    for i in xrange(node.getExecPortCount()):
        portName = node.getExecPortName(i)
        portConnectionType = PORT_TYPE_MAP[node.getExecPortType(i)]
        rtVal = nodeBind_.getArgValue(portName)
        portDataType = rtVal.getTypeName().getSimpleType()
    
        print("==================")
        print nodeName
        print(portName)
        print(portConnectionType)
        print(rtVal)
        print(portDataType)
    

    Thụy Nguyễn
    CG Artist

  • anhungxadieuanhungxadieu Posts: 107

    I want to confirm that only print default value of selected node, not the true value! :(

    Thụy Nguyễn
    CG Artist

Sign In or Register to comment.