SOLVED delete Redshift node

Is it possible to delete an Xpresso node using Python within a Redshift material? I am baking an object and when I move it to a new scene file, the user data parameters referenced inside the node are broken so I would like to remove the node.Screen Shot 2020-05-23 at 6.40.34 AM.png

Hi @Swinn, thanks for reaching out us.

With regard to your question, once you've retrieved the root from the GvNodeMaster, you can traverse the shader graph and considering that a GvNode inherits from a BaseList2D and consequently from GeListNode you can delete it by calling GeListNode::Remove().

Assuming this graph the code below deletes the noise node just by looking, for the sake of simplicity, at its name.
53b3f18a-c039-485d-8484-e85cc594f96c-image.png

...
    activeMat = doc.GetActiveMaterial()
    
    if activeMat is not None and activeMat.GetType() != 1036224:
        print "Active material is not a RedShift one"
        return
    
    outputNode = activeMat[c4d.REDSHIFT_GRAPH_NODES]
    if outputNode is None:
        print "Output node is not valid"
        return
    
    gvMaster = outputNode.GetNodeMaster()
    if gvMaster is None:
        print "NodeMaster is not valid"
        return
    
    gvRoot = gvMaster.GetRoot()
    if gvRoot is None:
        print "Root node is invalid"
        return
    
    currentNode = gvRoot.GetDown()
    while currentNode is not None:
        if currentNode.GetName() = "RS Noise":
            currentNode.Remove()
            break
        
        currentNode = currentNode.GetNext()
    
    print "Node removed"
...

Best, Riccardo

Hi @Swinn, thanks for reaching out us.

With regard to your question, once you've retrieved the root from the GvNodeMaster, you can traverse the shader graph and considering that a GvNode inherits from a BaseList2D and consequently from GeListNode you can delete it by calling GeListNode::Remove().

Assuming this graph the code below deletes the noise node just by looking, for the sake of simplicity, at its name.
53b3f18a-c039-485d-8484-e85cc594f96c-image.png

...
    activeMat = doc.GetActiveMaterial()
    
    if activeMat is not None and activeMat.GetType() != 1036224:
        print "Active material is not a RedShift one"
        return
    
    outputNode = activeMat[c4d.REDSHIFT_GRAPH_NODES]
    if outputNode is None:
        print "Output node is not valid"
        return
    
    gvMaster = outputNode.GetNodeMaster()
    if gvMaster is None:
        print "NodeMaster is not valid"
        return
    
    gvRoot = gvMaster.GetRoot()
    if gvRoot is None:
        print "Root node is invalid"
        return
    
    currentNode = gvRoot.GetDown()
    while currentNode is not None:
        if currentNode.GetName() = "RS Noise":
            currentNode.Remove()
            break
        
        currentNode = currentNode.GetNext()
    
    print "Node removed"
...

Best, Riccardo

Cool! Thanks. 🙂