SOLVED How can I modify the substance shader asset filepath for a material using C4DPy?

Hi, I'm wondering if it's possible to modify the shader properties for a C4D Shader Node via C4DPy. My goal is to modify this value.
d4a62d04-aaf0-4034-85a4-1135208e16a8-image.png
In the GUI, I could open up a console and get the corresponding node like this:

while current_node is not None:
    if current_node.GetName() == 'Base Color':
        break
    current_node = current_node.GetNext()

And then I could access the red-outlined variable through:
current_node[c4d.GV_REDSHIFT_BAKER_SHADER][c4d.SUBSTANCESHADER_ASSET][c4d.SUBSTANCEASSET_FILENAME], but this doesn't seem to work when using C4DPy, as current_node[c4d.GV_REDSHIFT_BAKER_SHADER][c4d.SUBSTANCESHADER_ASSET] yields None. How can I modify this parameter via C4DPy?

Dear community,

this question has been answered by mail and is unfortunately not available for the public in its entirety. The core of the answer was:

if node.GetName() == 'Base Color' and node.GetTypeName() == 'C4D Shader':

    # Import the new substance as an asset into the document.
    res, asset, _ = c4d.modules.substance.ImportSubstance(
        doc, substance_path, c4d.SUBSTANCE_IMPORT_COPY_NO, False, False, False)

    if res != c4d.SUBSTANCE_IMPORT_RESULT_SUCCESS:
        raise IOError(f"Could not load substance file: {substance_path}")

    # Create a shader for the substance asset.
    shader = c4d.modules.substance.CreateSubstanceShader(asset)
    if not isinstance(shader, c4d.BaseShader):
        raise MemoryError("Unable to allocate substance shader.")

    # Insert the new shader into the material and set the shader
    # as the shader of the C4D Shader node.
    material.InsertShader(shader)
    node[c4d.GV_REDSHIFT_BAKER_SHADER] = shader

Cheers,
Ferdinand

Hello @ajcav2,

Thank you for reaching out to us. We do understand your question, but there are many ifs and buts due to the abstract nature of your question. We could write code of our own to investigate your problem, but there would not be any guarantee that we will encounter the same bug/problem you are encountering.

Please provide an executable example of the problem and a demo file containing the scene you are trying to modify. And just to be sure: You are indeed using the c4dpy executable delivered with Cinema 4D and not the Python interpreter within Cinema 4D, right?

In case your file / setup contains intellectual property, which cannot be posted on the forum, you can reach out to us via sdk_support(at)maxon(dot)net.

Cheers,
Ferdinand

Hi @ferdinand , thanks for the response. Yes, we are using the c4dpy executable delivered with Cinema 4D when we run into this error. We do not see this issue when using the Python interpreter within Cinema 4D.

I'm not able to post our setup to the forum, so I've emailed the address you provided. Thanks!

Dear community,

this question has been answered by mail and is unfortunately not available for the public in its entirety. The core of the answer was:

if node.GetName() == 'Base Color' and node.GetTypeName() == 'C4D Shader':

    # Import the new substance as an asset into the document.
    res, asset, _ = c4d.modules.substance.ImportSubstance(
        doc, substance_path, c4d.SUBSTANCE_IMPORT_COPY_NO, False, False, False)

    if res != c4d.SUBSTANCE_IMPORT_RESULT_SUCCESS:
        raise IOError(f"Could not load substance file: {substance_path}")

    # Create a shader for the substance asset.
    shader = c4d.modules.substance.CreateSubstanceShader(asset)
    if not isinstance(shader, c4d.BaseShader):
        raise MemoryError("Unable to allocate substance shader.")

    # Insert the new shader into the material and set the shader
    # as the shader of the C4D Shader node.
    material.InsertShader(shader)
    node[c4d.GV_REDSHIFT_BAKER_SHADER] = shader

Cheers,
Ferdinand