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] LayerShader.AddLayer() -> Defining Shader

    General Talk
    5
    4
    7.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.
    • P
      PdZ 1
      last edited by PdZ 1

      Hello all,

      I tried everything to figure out how to use the newly added Python-Command "LayerShader.AddLayer()" in S24.
      As far as I know it only adds the "Type" of Layer. For Example I want to add a certain shader to the Layer I first use AddLayer(c4d.TypeShader) and this will give me an empty "Shader". But how can I define this shader to a specific Shader then?
      (https://developers.maxon.net/docs/py/2023_2/modules/c4d/C4DAtom/GeListNode/BaseList2D/BaseShader/LayerShader/index.html?highlight=addlayer#LayerShader.AddLayer)

      I tried everything but I dont get it... does someone know how to do it?

      Thx in advance!

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

        NOTE ( @ferdinand ) : The here provided code example contains an error, please refer to How to Create and Populate a Layer Shader? instead.

        Hi @PdZ-1 welcome in plugincafe.

        The type need to be one of the LayerType.
        So to have a regular BaseShader you first need to create a TypeShader layer and then set the link.
        Find a code snippet

        import c4d
        
        
        # Main function
        def main():
            # Retrieveh teh Layer Shader
            mat = doc.GetFirstMaterial()
            sha_xlayer = mat.GetFirstShader()
            
            # Create an HSL layer
            hsl = sha_xlayer.AddLayer(c4d.TypeHSL)
            
            # Create a Shader Layer
            shader_layer = sha_xlayer.AddLayer(c4d.TypeShader)
            
            # Create a Gradient Shader
            gradient_shader = c4d.BaseShader(c4d.Xgradient)
            
            # Insert this gradient to the material (so the material become the owner of this shader too)
            mat.InsertShader(gradient_shader, sha_xlayer)
            
            # Finally set the Shader Layer link to the Gradient Shader
            shader_layer.SetParameter(c4d.LAYER_S_PARAM_SHADER_LINK, gradient_shader)
        
            c4d.EventAdd()
        
        # Execute main()
        if __name__=='__main__':
            main()
        

        Cheers,
        Maxime.

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

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

          Hello @PdZ-1,

          without further questions or replies, we will consider this topic as solved by Monday, the 30th and flag it accordingly.

          Thank you for your understanding,
          Ferdinand

          MAXON SDK Specialist
          developers.maxon.net

          1 Reply Last reply Reply Quote 0
          • indexofrefractionI
            indexofrefraction
            last edited by indexofrefraction

            Hi... I'm trying to figure out how to handle nested LayerShaders

            mat.InsertShader(gradient_shader, sha_xlayer) inserts gradient_shader as a child of sha_xlayer ?
            Would sha_xlayer.InsertShader(gradient_shader) do exactly the same thing ?

            If yes, does mat.InsertShader(sha_xlayer) have to be done first as well,
            or can you set up a shader tree first and then add it to the material?

            best, index

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