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

    DescID and DescLevel for Shader Layers and properties

    Cinema 4D SDK
    2025 python windows
    2
    3
    47
    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
      alcol68
      last edited by

      So, I am working on a couple things dealing with layer shaders from a Shader Field.

      1.) Adding ports to an Object Xpresso Operator with the Shader as the linked object.
      2.) Adding keyframes to an animation track for the Gradient in a Gradient Layer of the Shader.

      I have had no issue creating XPresso nodes and ports in general. As an example, here is a snippet of how I add ports for object operators:

      ObjectNode = NodeMaster.CreateNode(Root,c4d.ID_OPERATOR_OBJECT, insert=None, x=700, y=850)
      
      ObjectNode.SetParameter(c4d.DescID(c4d.GV_OBJECT_OBJECT_ID), Null, c4d.DESCFLAGS_SET_NONE)
      
      ObjectNodeIn = ObjectNode.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(c4d.ID_BASEOBJECT_GLOBAL_POSITION)), flag=c4d.GV_PORT_FLAG_IS_VISIBLE, message=False)
      

      I can add an object operator, and link the shader to the object operator, but I am having trouble creating the ports using the DescID and DescLevels, simply because I’m not sure what IDs to use in the DescLevel to access the parameters (as shown in the image below).

      Similarly, I have no problems creating tracks and keys for animated parameters, so long as I know the DescID and DescLevels for those parameters. I have combed through the forum and SDKs, and can’t seem to find how to access the shader layer parameters through this method. I also have no problem creating Shader Layers and accessing their parameters after instantiation, but not how to reference them through the DescLevel method.

      Here is an example of how I set key and tracks normally:

      pid_pmix = c4d.DescID(c4d.DescLevel(c4d.ID_USERDATA, c4d.DTYPE_SUBCONTAINER, 0), c4d.DescLevel(4))
      
      mixtrack = c4d.CTrack(Xpresso, pid_pmix)
      
      Xpresso.InsertTrackSorted(mixtrack)
      
      defkey, dub = doc.GetDefaultKey()
      
      mixcurve = mixtrack.GetCurve()
      
      mixval1 = 0
      
      mixkey1 = defkey.GetClone()
      
      mixkey1.SetValue(mixcurve, mixval1)
      
      mixkey1.SetTime(mixcurve, c4d.BaseTime(46/20))
      
      mixcurve.InsertKey(mixkey1, True
      

      As mentioned above, the only problem I’m having is finding and accessing the DescLevel IDs for the shader layers and their properties for these two scenarios. I am currently working on C4D 2025.2.0. Any advice or direction would be greatly appreciated. Thank you.

      dev post.PNG

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

        Hey @alcol68,

        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: How to Ask Questions.

        About your First Question

        Your question is a little bit ambiguous in what DescID you are looking for a layer shader, you probably mean the properties of one of its children and not the layer shader itself. I would recommend to have a look at BaseShader: Access and Structure (C++) to understand how shaders are nested. You can then check out this posting for how to manipulate a layer shader in Python where I also documented its more fringe parameters.

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

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

          I have previously looked at the “How to Create and Populate a Layer Shader” post. The shader that I am referencing above, I can easily create using those same methods. Below is the code for creating the Shader I am working with:

          Field1 = doc.SearchObject("Shader Field")
          Shader = c4d.LayerShader()
          
          ShaderLayer1 = Shader.AddLayer(c4d.TypeShader)
          GradientShader1 = c4d.BaseList2D(c4d.Xgradient)
          GradientShader1[c4d.ID_BASELIST_NAME] = "Gradient Circular"
          GradientShader1[c4d.SLA_GRADIENT_TYPE] = c4d.SLA_GRADIENT_TYPE_2D_CIRC
          GradientShader1[c4d.SLA_GRADIENT_CYCLE] = False
          GradientShader1[c4d.SLA_GRADIENT_ANGLE] = 3.14159
          Gradient1 = GradientShader1[c4d.SLA_GRADIENT_GRADIENT]
          Gradient1.FlushKnots()
          Gradient1.InsertKnot(c4d.Vector(0,0,0), 1, 0, 0.5, 0)
          Gradient1.InsertKnot(c4d.Vector(0,0,0), 1, 1, 0.5, 1)
          GradientShader1[c4d.SLA_GRADIENT_GRADIENT] = Gradient1
          GradientShader1.InsertUnder(Shader)
          ShaderLayer1.SetParameter(c4d.LAYER_S_PARAM_SHADER_LINK, GradientShader1)
          
          ShaderLayer2 = Shader.AddLayer(c4d.TypeShader)
          GradientShader2 = c4d.BaseList2D(c4d.Xgradient)
          GradientShader2[c4d.ID_BASELIST_NAME] = "Gradient U"
          GradientShader2[c4d.SLA_GRADIENT_CYCLE] = False
          GradientShader2[c4d.SLA_GRADIENT_ANGLE] = 3.14159
          Gradient2 = GradientShader1[c4d.SLA_GRADIENT_GRADIENT]
          Gradient2.FlushKnots()
          Gradient2.InsertKnot(c4d.Vector(0,0,0), 1, 0.125, 0.5, 0)
          Gradient2.InsertKnot(c4d.Vector(1,1,1), 1, 1, 0.5, 1)
          GradientShader2[c4d.SLA_GRADIENT_GRADIENT] = Gradient2
          GradientShader2.InsertUnder(Shader)
          ShaderLayer2.SetParameter(c4d.LAYER_S_PARAM_SHADER_LINK, GradientShader2)
          
          ShaderLayer3 = Shader.AddLayer(c4d.TypeShader)
          NoiseShader = c4d.BaseList2D(c4d.Xnoise)
          NoiseShader[c4d.SLA_NOISE_COLOR1] = c4d.Vector(1,1,1)
          NoiseShader[c4d.SLA_NOISE_COLOR2] = c4d.Vector(0,0,0)
          NoiseShader[c4d.SLA_NOISE_SEED] = 666
          NoiseShader[c4d.SLA_NOISE_GLOBAL_SCALE] = 2
          NoiseShader[c4d.SLA_NOISE_ANI_SPEED] = 1
          NoiseShader[c4d.SLA_NOISE_CONTRAST] = 1
          NoiseShader.InsertUnder(Shader)
          ShaderLayer3.SetParameter(c4d.LAYER_S_PARAM_SHADER_LINK, NoiseShader)
          ShaderLayer3.SetParameter(c4d.LAYER_S_PARAM_SHADER_MODE, 11)
          
          ShaderLayer4 = Shader.AddLayer(c4d.TypeTransform)
          ShaderLayer4.SetParameter(c4d.LAYER_S_PARAM_TRANS_ANGLE, 3.14159)
          Field1.InsertShader(Shader)
          Field1[c4d.ID_MG_SHADER_SHADER] = Shader
          

          Using the port-creation example I gave before, for an object operator, I use the DescLevel to get the ID of the property I want to create a port for. In the above example, I use the integer “c4d.ID_BASEOBJECT_GLOBAL_POSITION.” Then if I want to use the specific Z parameter, I use the second level integer of “c4d.VECTOR_Z.”

          I assume there is a similar level system to grab the angle parameter of the Transform layer in my Shader. The Shader itself is linked to the object operator, so accessing its layers should be the first level.

          ObjectNode.AddPort(c4d.GV_PORT_INPUT, c4d.DescID(c4d.DescLevel(c4d.SLA_LAYER_BLEND), c4d.DescLevel(c4d.LAYER_S_PARAM_TRANS_ANGLE)), flag=c4d.GV_PORT_FLAG_IS_VISIBLE, message=False)
          

          If I use just the single level integer of “c4d. LAYER_S_PARAM_TRANS_ANGLE” the port is not created. So, I assume there is another level above this one that needs to be called as well, namely the actual Transform layer itself. But I don’t know how to call that layer as an integer in the DescLevel method, because I cannot pass an object (“ShaderLayer4” from my above creation code) in the integer parameter of DescLevel. I used the placeholder of “c4d.SLA_LAYER_BLEND” as that first level, but it creates an empty port, not the angle parameter port. Using “c4d.TypeTransform” or “c4d. LAYER_S_PARAM_ALL_ACTIVE” do not work either.

          This is what I am trying to figure out: What is the integer that I need to use in order to access the Transform Layer itself to use in the DescLevel method, to use in the AddPort method? Unless there is a different way to add a port, I cannot find any information on this particular issue.

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