UNSOLVED [Python] Edit Parameters on nodes?

Hi Experts,

I´m trying to develop a little python script that imports Substance Textures, creates Redshift materials and connects all the right textures.

But i'm having a hard time figuring out how to edit parameters on nodes.

Example:
I inserts a texture node with the following code:

textureNode = graph.AddChild('', maxon.Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler"), maxon.DataDictionary())

That works like a champ, and i can easily wire in/out ports.

But how do i change the values in the "Texture node" i just created? (Path to texture, Color Space, etc)

Looking forward to hear from you guys 😉

I had occasion to do this recently and it's all explained in the Redshift Renderer section of the SDK documentation. Basically, you access the port and set its default value. There's an extra step for adding a bitmap to a texture node, but it's the same principle.

Steve

Hello

Here is my little Redshift api helper on Github , it have a AddTexture function to do this .

It is a bare-bone one , and I have no time to perfection , but it can work for basic for now

It has a little example , welcome to improve it and have fun 😊

Hope it can help for anyway .

@spedler Thanks mate, using fictive input ports did the trick 😉
@Dunhou Wauw, that's a great Custom API, this makes it soooo much easier. Thanks a bunch Dunhou 😉

Hi @sortsovs once you have the node, you need to retrieve the appropriate port. Be careful as some port can be nested.
Then once you have the correct port, you need to call GraphNode.SetDefaultValue.
When calling SetDefaultValue it is important to pass a maxon data as the current Python system is not able to automatically guess the expected result.

Find bellow an example to create a Redshift Material with a Texture Node with a custom path and name.

import c4d
import maxon

REDSHIFT_NODESPACE_ID = maxon.Id("com.redshift3d.redshift4c4d.class.nodespace")

def CreateTextureNode(gr: maxon.GraphModelRef, nodeName: str, texturePath: str, isLinear:bool=False) -> maxon.GraphNode:
    # Start a transaction to inform the graph that a modification is going to happen
    with gr.BeginTransaction() as transaction:
        
        # Create a Redshift Texture Node and rename it
        textureNodeId = maxon.Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler")
        texNode = gr.AddChild("", textureNodeId, maxon.DataDictionary())
        texNode.SetValue("net.maxon.node.base.name", maxon.String(nodeName))
        
        # Retrieve path and gammage override port
        path = texNode.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0").FindChild("path")
        gammaOverride = texNode.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0_gammaoverride")

        # Define the value stored by the node for these port when no connection exist
        gammaOverride.SetDefaultValue(maxon.Bool(isLinear))
        path.SetDefaultValue(maxon.Url(texturePath))

        # Push the change to the graph
        transaction.Commit()

    return texNode

def main() -> None:
    # Create a BaseMaterial in the active document
    rsMat = c4d.BaseMaterial(c4d.Mmaterial)
    doc.InsertMaterial(rsMat)
    
    # Retrieve it node material part and create a Redshift Graph
    nMat = rsMat.GetNodeMaterialReference()
    nMat.AddGraph(REDSHIFT_NODESPACE_ID)
    gr = nMat.GetGraph(REDSHIFT_NODESPACE_ID)

    # Create a texture node
    albedoTexNode = CreateTextureNode(gr, "Albedo", r"C:/PathToATexture.jpg")
    c4d.EventAdd()


if __name__ == '__main__':
    main()

Cheers,
Maxime.