Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Get/Fetch Node from an Existing Xpresso Tag

    Cinema 4D SDK
    r20 python
    2
    3
    671
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bentraje
      last edited by

      Hi,

      Is there a way to get/fetch a node from an existing xpresso tag? For instance, of all 5 existing math nodes, select a node with a particular name or a particular operation type (i.e. multiply as opposed to add).

      In the documentation there is GetNode method but it is specific to port. Basically, what I am after is something like.

      obj = doc.SearchObject("obj")
      tag = obj.GetTag(c4d.Texpresso)
      nodemaster = tag.GetNodeMaster()
      
      # get/fetch a particular node  in  the list of nodes of nodemaster
      
      

      Is this possible? Thank you for looking at my problem.

      1 Reply Last reply Reply Quote 0
      • M
        m_adam
        last edited by m_adam

        Hi @bentraje GvNode are standard BaseList2 that means you can iterate them as you can iterate object in the ObjectManager.

        With that's said here is an example:

        """
        Copyright: MAXON Computer GmbH
        
        Author: Maxime Adam
        
        Description:
            - Loops through all nodes from the Xpresso Tag of the selected object.
            - Checks if it's a Math Node.
        
        Class/method highlighted:
            - c4d.modules.graphview.GvNodeMaster
            - c4d.modules.graphview.GvNode
            - GvNodeMaster.GetRoot()
            - GvNode.GetNext() / GvNode.GetUp() / GvNode.GetDown()
            - GvNode.GetOperatorID()
        
        Compatible:
            - Win / Mac
            - R13, R14, R15, R16, R17, R18, R19, R20
        """
        import c4d
        
        
        def iterateNodes(node):
            """
            This function iterates over a BaseList2D, GvNode inherit from BaseList2D.
            :param node: GvNode to iterate.
            """
            while node:
                nodeName = node.GetName()
                isMathNode = node.GetOperatorID() == c4d.ID_OPERATOR_MATH
                
                # If it's a math node and set to multiply, prints the node name
                if isMathNode:
                    isMultiply = node[c4d.GV_MATH_FUNCTION_ID] == c4d.GV_MUL_NODE_FUNCTION
                    if isMultiply:
                        print "Name: {0}".format(node.GetName())
        
                # If it's a group retrieves all inner GvNode.
                if node.IsGroupNode():
                    iterateNodes(node.GetDown())
        
                node = node.GetNext()
        
        def main():
            # Checks if selected object is valid
            if op is None:
                raise ValueError("op is none, please select one object.")
        
            # Retrieves the xpresso Tag
            xpressoTag = op.GetTag(c4d.Texpresso)
            if xpressoTag is None:
                raise ValueError("Make sure the selected object get an Xpresso Tag.")
        
            # Retrieves the node master
            gvNodeMaster = xpressoTag.GetNodeMaster()
            if gvNodeMaster is None:
                raise RuntimeError("Failed to retrieves the Node Master.")
        
            # Retrieves the Root node (the Main XGroup) that holds all others nodes
            gvRoot = gvNodeMaster.GetRoot()
            if gvRoot is None:
                raise RuntimeError("Failed to retrieves the Root Node.")
        
            # Iterates overs all nodes of this root node.
            iterateNodes(gvRoot)
        
        
        if __name__=='__main__':
            main()
        

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 2
        • B
          bentraje
          last edited by

          Thanks @m_adam. Works as expected.
          My bad, I was looking at the documentation hierarchy erroneously (i.e c4d > modules > graphview > GvNode)

          Just a note: I think the if Multiply: line is supposed to be if isMultiply:.

          Thanks again. Have a great day ahead!

          1 Reply Last reply Reply Quote 1
          • First post
            Last post