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
    • Register
    • Register
    • Login

    How can I modify the substance shader asset filepath for a material using C4DPy?

    Cinema 4D SDK
    python
    2
    4
    507
    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.
    • A
      ajcav2
      last edited by

      Hi, I'm wondering if it's possible to modify the shader properties for a C4D Shader Node via C4DPy. My goal is to modify this value.
      d4a62d04-aaf0-4034-85a4-1135208e16a8-image.png
      In the GUI, I could open up a console and get the corresponding node like this:

      while current_node is not None:
          if current_node.GetName() == 'Base Color':
              break
          current_node = current_node.GetNext()
      

      And then I could access the red-outlined variable through:
      current_node[c4d.GV_REDSHIFT_BAKER_SHADER][c4d.SUBSTANCESHADER_ASSET][c4d.SUBSTANCEASSET_FILENAME], but this doesn't seem to work when using C4DPy, as current_node[c4d.GV_REDSHIFT_BAKER_SHADER][c4d.SUBSTANCESHADER_ASSET] yields None. How can I modify this parameter via C4DPy?

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @ajcav2
        last edited by

        Hello @ajcav2,

        Thank you for reaching out to us. We do understand your question, but there are many ifs and buts due to the abstract nature of your question. We could write code of our own to investigate your problem, but there would not be any guarantee that we will encounter the same bug/problem you are encountering.

        Please provide an executable example of the problem and a demo file containing the scene you are trying to modify. And just to be sure: You are indeed using the c4dpy executable delivered with Cinema 4D and not the Python interpreter within Cinema 4D, right?

        In case your file / setup contains intellectual property, which cannot be posted on the forum, you can reach out to us via sdk_support(at)maxon(dot)net.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • A
          ajcav2
          last edited by

          Hi @ferdinand , thanks for the response. Yes, we are using the c4dpy executable delivered with Cinema 4D when we run into this error. We do not see this issue when using the Python interpreter within Cinema 4D.

          I'm not able to post our setup to the forum, so I've emailed the address you provided. Thanks!

          ferdinandF 1 Reply Last reply Reply Quote 1
          • ferdinandF
            ferdinand @ajcav2
            last edited by

            Dear community,

            this question has been answered by mail and is unfortunately not available for the public in its entirety. The core of the answer was:

            if node.GetName() == 'Base Color' and node.GetTypeName() == 'C4D Shader':
            
                # Import the new substance as an asset into the document.
                res, asset, _ = c4d.modules.substance.ImportSubstance(
                    doc, substance_path, c4d.SUBSTANCE_IMPORT_COPY_NO, False, False, False)
            
                if res != c4d.SUBSTANCE_IMPORT_RESULT_SUCCESS:
                    raise IOError(f"Could not load substance file: {substance_path}")
            
                # Create a shader for the substance asset.
                shader = c4d.modules.substance.CreateSubstanceShader(asset)
                if not isinstance(shader, c4d.BaseShader):
                    raise MemoryError("Unable to allocate substance shader.")
            
                # Insert the new shader into the material and set the shader
                # as the shader of the C4D Shader node.
                material.InsertShader(shader)
                node[c4d.GV_REDSHIFT_BAKER_SHADER] = shader
            

            Cheers,
            Ferdinand

            MAXON SDK Specialist
            developers.maxon.net

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