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

    [Python] Edit Parameters on nodes?

    General Talk
    4
    5
    1.1k
    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.
    • S
      sortsovs
      last edited by sortsovs

      Hi Experts,

      I´m trying to develop a little python script that imports Substance Textures, creates Redshift materials and connects all the right textures.

      But i'm having a hard time figuring out how to edit parameters on nodes.

      Example:
      I inserts a texture node with the following code:

      textureNode = graph.AddChild('', maxon.Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler"), maxon.DataDictionary())
      

      That works like a champ, and i can easily wire in/out ports.

      But how do i change the values in the "Texture node" i just created? (Path to texture, Color Space, etc)

      Looking forward to hear from you guys 😉

      1 Reply Last reply Reply Quote 0
      • S
        spedler
        last edited by

        I had occasion to do this recently and it's all explained in the Redshift Renderer section of the SDK documentation. Basically, you access the port and set its default value. There's an extra step for adding a bitmap to a texture node, but it's the same principle.

        Steve

        1 Reply Last reply Reply Quote 0
        • DunhouD
          Dunhou
          last edited by Dunhou

          Hello

          Here is my little Redshift api helper on Github , it have a AddTexture function to do this .

          It is a bare-bone one , and I have no time to perfection , but it can work for basic for now

          It has a little example , welcome to improve it and have fun 😊

          Hope it can help for anyway .

          https://boghma.com
          https://github.com/DunHouGo

          1 Reply Last reply Reply Quote 0
          • S
            sortsovs
            last edited by

            @spedler Thanks mate, using fictive input ports did the trick 😉
            @Dunhou Wauw, that's a great Custom API, this makes it soooo much easier. Thanks a bunch Dunhou 😉

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

              Hi @sortsovs once you have the node, you need to retrieve the appropriate port. Be careful as some port can be nested.
              Then once you have the correct port, you need to call GraphNode.SetDefaultValue.
              When calling SetDefaultValue it is important to pass a maxon data as the current Python system is not able to automatically guess the expected result.

              Find bellow an example to create a Redshift Material with a Texture Node with a custom path and name.

              import c4d
              import maxon
              
              REDSHIFT_NODESPACE_ID = maxon.Id("com.redshift3d.redshift4c4d.class.nodespace")
              
              def CreateTextureNode(gr: maxon.GraphModelRef, nodeName: str, texturePath: str, isLinear:bool=False) -> maxon.GraphNode:
                  # Start a transaction to inform the graph that a modification is going to happen
                  with gr.BeginTransaction() as transaction:
                      
                      # Create a Redshift Texture Node and rename it
                      textureNodeId = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler")
                      texNode = gr.AddChild("", textureNodeId, maxon.DataDictionary())
                      texNode.SetValue("net.maxon.node.base.name", maxon.String(nodeName))
                      
                      # Retrieve path and gammage override port
                      path = texNode.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0").FindChild("path")
                      gammaOverride = texNode.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0_gammaoverride")
              
                      # Define the value stored by the node for these port when no connection exist
                      gammaOverride.SetDefaultValue(maxon.Bool(isLinear))
                      path.SetDefaultValue(maxon.Url(texturePath))
              
                      # Push the change to the graph
                      transaction.Commit()
              
                  return texNode
              
              def main() -> None:
                  # Create a BaseMaterial in the active document
                  rsMat = c4d.BaseMaterial(c4d.Mmaterial)
                  doc.InsertMaterial(rsMat)
                  
                  # Retrieve it node material part and create a Redshift Graph
                  nMat = rsMat.GetNodeMaterialReference()
                  nMat.AddGraph(REDSHIFT_NODESPACE_ID)
                  gr = nMat.GetGraph(REDSHIFT_NODESPACE_ID)
              
                  # Create a texture node
                  albedoTexNode = CreateTextureNode(gr, "Albedo", r"C:/PathToATexture.jpg")
                  c4d.EventAdd()
              
              
              if __name__ == '__main__':
                  main()
              

              Cheers,
              Maxime.

              MAXON SDK Specialist

              Development Blog, MAXON Registered Developer

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