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 - How to insert knots in c4d.Gradient

    Cinema 4D SDK
    python
    2
    3
    432
    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.
    • V
      Vladislav Borovikov
      last edited by

      Hello everyone!
      I'm trying to add knots to the c4d.Gradient object, in GvNode. But the changes are not applied to the parameter, maybe I missed something, and this parameter needs to be updated?

      import c4d
      import redshift
      
      knots = [
          (c4d.Vector(1,0,1), 0.25, 0.25, 0.25),
          (c4d.Vector(0,1,1), 0.5, 0.5, 0.5),
          (c4d.Vector(1,1,0), 0.75, 0.75, 0.75),
          
      ]
      
      def main() -> None:
          rs_material = doc.GetActiveMaterial()
          if not rs_material.GetTypeName() == "RS Shader Graph":
              print(rs_material.GetTypeName())
              return
          
          # Get node master and root
          nm = redshift.GetRSMaterialNodeMaster(rs_material)
          root = nm.GetRoot()
          
          # Create RSRamp gvNode
          ramp_node = nm.CreateNode(root, 1036227)
          ramp_node[c4d.GV_REDSHIFT_SHADER_META_CLASSNAME] = 'RSRamp'
          
          # Get Gradient
          gradient = ramp_node[c4d.REDSHIFT_SHADER_RSRAMP_RAMP]
          gradient.FlushKnots()
          for i, knot in enumerate(knots):
              gradient.InsertKnot(knot[0], knot[1], knot[2], knot[3], i )
          
          #  Check values
          for i in range(gradient.GetKnotCount()):
              knot = gradient.GetKnot(i)
              col = knot.get("col")
              pos = knot.get("pos")
              br = knot.get('brightness')
              print(f"col = {col}, pos = {pos}, brightness = {br} ")
      
      main()
      
      i_mazlovI 1 Reply Last reply Reply Quote 0
      • i_mazlovI
        i_mazlov @Vladislav Borovikov
        last edited by i_mazlov

        Hi @Vladislav-Borovikov,

        Welcome to the Maxon developers forum and its 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 procedures. You did not do anything wrong, we point all new users to these rules.

        • Forum Overview: Provides a broad overview of the fundamental structure and rules of this forum, such as the purpose of the different sub-forums or the fact that we will ban users who engage in hate speech or harassment.
        • Support Procedures: Provides a more in detail overview of how we provide technical support for APIs here. This topic will tell you how to ask good questions and limits of our technical support.
        • Forum Features: Provides an overview of the technical features of this forum, such as Markdown markup or file uploads.

        It is strongly recommended to read the first two topics carefully, especially the section Support Procedures: Asking Questions.

        About your First Question

        Custom datatypes implement copy constructor, which effectively means that at the line

        gradient = ramp_node[c4d.REDSHIFT_SHADER_RSRAMP_RAMP]
        

        you copy c4d.Gradient from the node and store it in variable 'gradient'. All further interactions are performed with this local copy of the gradient. In order to apply them back to the node you need to assign your local variable after modifications back to the node:

        ramp_node[c4d.REDSHIFT_SHADER_RSRAMP_RAMP] = gradient
        

        Cheers,
        Ilia

        MAXON SDK Specialist
        developers.maxon.net

        V 1 Reply Last reply Reply Quote 0
        • V
          Vladislav Borovikov @i_mazlov
          last edited by

          Thank you very much, @i_mazlov! This is what I needed!

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