Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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

    How to access to the Layer Shader parameters?

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 501 Views
    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.
    • H Offline
      Helper
      last edited by

      On 19/12/2016 at 19:33, xxxxxxxx wrote:

      Hello there,

      How to access to the Layer Shader parameters of the Color channel for example. (See the screenshot below)

      I want to Enable/Disable layers using python, is it possible to do that?

      Thanks.

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 20/12/2016 at 03:02, xxxxxxxx wrote:

        Hi,

        A layer shader is represented by the class LayerShader.
        First access the color channel of the material to retrieve it. Then call LayerShader.GetFirstLayer() to retrieve the first layer of the shader.
        To loop through all the layers use LayerShaderLayer.GetNext() until it returns None.
        To enable or disable a layer change LAYER_S_PARAM_ALL_ACTIVE parameter with LayerShaderLayer.SetParameter().
        Layer parameter IDs aren't documented in the Python API currently but they can be found in the C++ SDK docs here.

        Here's a simple script that enables the first Layer of a Layer Shader:

        import c4d
          
        def main() :
            mat = doc.GetFirstMaterial()
            if mat is None:
                return
          
            shader = mat[c4d.MATERIAL_COLOR_SHADER]
            if shader is None or shader.GetType() != c4d.Xlayer:
                return
          
            layer = shader.GetFirstLayer()
            if layer is None:
                return
          
            layer.SetParameter(c4d.LAYER_S_PARAM_ALL_ACTIVE, True)
            shader.Message(c4d.MSG_CHANGE)
            c4d.EventAdd()
          
          
        if __name__=='__main__':
            main()
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          On 20/12/2016 at 10:36, xxxxxxxx wrote:

          Thank you Yannick,

          I tried this script in C4D R14 and I have obtained this error message :
          AttributeError: 'c4d.BaseShader' object has no attribute 'GetFirstLayer'

          Is it possible to do that with R14?

          PS : Tested with R17 and it works.

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            On 20/12/2016 at 10:56, xxxxxxxx wrote:

            LayerShader class is implemented in R17.032. So you must do it in C++ if you want to support R14.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              On 21/12/2016 at 10:10, xxxxxxxx wrote:

              I have find an alternative to do that in Cinema 4D R14, in combining Python and XPresso, but thanks all the same.

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