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

    Is there any way to trriger the GraphNode "Add Layer" button with Python?

    Cinema 4D SDK
    2024 windows python
    2
    4
    667
    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.
    • K
      karen
      last edited by

      As shown in the following screenshot.
      fd38b880-c0a6-44cd-b455-1ff94328969a-image.png
      It's Vray NodeMaterial in the picture,but I found the same structure in scene_root Node and the C4D NodeMaterial.
      I had tried GraphNode.SetValue and GraphNode.SetDefaultValue.but I don't know how to set the "value" because it's a Array<Tuple<Id, DataDictionary>> Type.
      I did write some codes and I know that they are wrong.But I dont know how to correct it.

      from typing import Optional
      import c4d
      import maxon
      
      doc: c4d.documents.BaseDocument  # The active document
      op: Optional[c4d.BaseObject]  # The active object, None if unselected
      
      
      
      
      def main() -> None:
          material = doc.GetActiveMaterial()
          nodeMaterial = material.GetNodeMaterialReference()
          graph: maxon.GraphModelInterface = nodeMaterial.GetGraph(c4d.GetActiveNodeSpaceId())
      
          layered_list = []
          maxon.GraphModelHelper.FindNodesById(graph,"com.chaos.vray_node.texlayeredmax.texture_layers",maxon.NODE_KIND.INPORT, maxon.PORT_DIR.INPUT, False, layered_list)
          layered_node = layered_list[0]
      
      
          
          with graph.BeginTransaction() as transaction:
              data_dict:maxon.DataDictionary = {}
              key = "net.maxon.node.attribute.insertindex"
              value = 1
              data_dict[key] = value
              tuple_l = ["_0",data_dict]
              array = {tuple_l}
      
              layered_node.SetDefaultValue(array)
              
              transaction.Commit()
      
      
      
          print(tuple_l)
      
      
      if __name__ == '__main__':
          main()
      

      thanks.

      1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov
        last edited by

        Hello @karen ,

        Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!

        Getting Started

        Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:

        • Support Procedures: Scope of Support: Lines out the things we will do and what we will not do.
        • Support Procedures: Confidential Data: Most questions should be accompanied by code but code cannot always be shared publicly. This section explains how to share code confidentially with Maxon.
        • Forum Structure and Features: Lines out how the forum works.
        • Structure of a Question: Lines out how to ask a good technical question. It is not mandatory to follow this exactly, but you should follow the idea of keeping things short and mentioning your primary question in a clear manner.

        About your First Question

        Unfortunately, no, you cannot trigger this UI button. This is a frequent stumbling block when trying to interact with C4D existing UI elements.

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        K 1 Reply Last reply Reply Quote 0
        • K
          karen @i_mazlov
          last edited by

          Hi! @i_mazlov ,
          Thanks for your reply,I will take a look at the Forum and Support Guidelines.
          About the question
          Is there any other way to 'add layer' to the node other than ‘’press‘’ the button?

          1 Reply Last reply Reply Quote 0
          • K
            karen
            last edited by karen

            I found the AddPorts() Method,Sorry I missed it before.

            from typing import Optional
            import c4d
            import maxon
            
            doc: c4d.documents.BaseDocument  # The active document
            op: Optional[c4d.BaseObject]  # The active object, None if unselected
            
            def main() -> None:
                material = doc.GetActiveMaterial()
                nodeMaterial = material.GetNodeMaterialReference()
                graph: maxon.GraphModelInterface = nodeMaterial.GetGraph(c4d.GetActiveNodeSpaceId())
                
                with graph.BeginTransaction() as transaction:
                    
                    layered_node = graph.AddChild(maxon.Id(),"com.chaos.vray_node.texlayeredmax")
                    layers = layered_node.GetInputs().FindChild("com.chaos.vray_node.texlayeredmax.texture_layers") #The Layers portbundle
                    layers.AddPorts(2, 1) #Add layers
            
                    transaction.Commit()
                
                
                #Layer in Layers portbundle
                layers_list = []
                layers.GetChildren(layers_list,maxon.NODE_KIND.INPORT)
                
                #Textureports and BlendMode_ports in Layers portbundle
                layers_texport_list = [tport for port in layers_list if (tport := port.FindChild("com.chaos.vray.portbundle.texture_layer.texture"))]
                layers_mode_list = [mport for port in layers_list if (mport := port.FindChild("com.chaos.vray.portbundle.texture_layer.blend_mode"))]
                
                
                print(layered_node)
                print(layers)
                print(layers_list)
                print(layers_texport_list)
                print(layers_mode_list)
            
            
            if __name__ == '__main__':
                main()
            
            1 Reply Last reply Reply Quote 1
            • First post
              Last post