UNSOLVED [Python] LayerShader.AddLayer() -> Defining Shader

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?

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

Thx in advance!

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)


# Execute main()
if __name__=='__main__':