SOLVED Iterate through all Inputs and Outputs of a Given Node?


I'm trying to retrieve inputs and outputs of a selected node. But it gives me error when using the result from the GetInputs or GetOutputs method

    def RetrieveInformationOfNode(node):
        port = node.GetOutputs()
        for p in port:
            print ( # or p.GetName. Not sure. I can't receah this part of the code. 
        return True

    graph.GetSelectedNodes(RetrieveInformationOfNode, maxon.frameworks.graph.NODE_KIND.ALL_MASK)

The error:
TypeError: 'GraphNode' object is not iterable
But the documentation says Output port list of this node.
Isn't a list iterable?


GetInputs/GetOuputs return a GraphNode. This Graphnode contains all the Inputs or the Outputs port that the Node contains but they are a child of this GraphNode. As this is still a GraphNode, you need to use one of those function. GetChildren, GetInnerNodes.

import c4d
import maxon

# Display the outputs ports of the selected nodes in the active NodeMaterial of the Active Nodespace.

def main():
    # Retrieve the selected BaseMaterial
    mat = doc.GetActiveMaterial()
    if mat is None:
        raise ValueError("There is no selected BaseMaterial")

    # Retrieve the reference of the material as a node material.
    nodeMaterial = mat.GetNodeMaterialReference()
    if nodeMaterial is None:
        raise ValueError("Cannot retrieve node material reference")

    # Retrieve the current node space Id
    nodespaceId = c4d.GetActiveNodeSpaceId()

    # Retrieve the graph corresponding to that node space.
    graph = nodeMaterial.GetGraph(nodespaceId)
    if graph is None:
        raise ValueError("Cannot retrieve the graph of this nimbus ref")

    def DisplayOutputs(node):
        # Will display node information
        def PrintNodeInformation(port):
            # Print here the needed information
            print (port)

        def DisplayChildren(node):
            # Check if the node is valid and recursively display children.
            if not node.IsValid():
                return True
            return True

        # Retrieve the outputs port and the first level of children with GetChildren.
        return True

    # Retrieve the nodes that are selected and passed them to the function DisplayOutputs.
    maxon.GraphModelHelper.GetSelectedNodes(graph,  maxon.NODE_KIND.NODE, DisplayOutputs)
    print('---------------- using Inner')
    # using GetInnerNodes
    def DisplayInner(node):
        def PrintNode(port):
            return True
        node.GetInnerNodes(maxon.NODE_KIND.OUT_MASK, False, PrintNode) 
        return True

    maxon.GraphModelHelper.GetSelectedNodes(graph,  maxon.NODE_KIND.NODE, DisplayInner)

if __name__ == "__main__":


Ah so I guess there's really no port object. Everything is graph node object.
How would I know the object is an actual node or a port of an node?
Wouldn't it have been better if there is an actual port object and have just the port object a subclass of a the graph node so it inherits the methods?

P.S. The script works as expected, athough I have to modify it to work for R25.


you can have a look at this page you can see that GraphNode elements can be represented by a hierarchy. As written in that page, to know the node kind, use GetKind. That will return you its NODE_KIND.

There is no "ports" class, only GraphNode. The implementation does not always reflect what the user sees.



ah gotcha. the node kinda. thanks.
will close this thread for now.