SOLVED Redshift deleting using old information

Because data is coming from User Data, do I need additional info as per this post?


There are quite a few hoops to jump through, but this example should get you the idea.

import c4d

def get_port_descid(node, port):
    """Returns the DescID for a ``GvPort``.

    If all our ports would be for static description elements, this would be
    easy. It would be just ``port.GetSubID()``. Unfortunately we are dealing
    with a lot of dynamic descriptions in the context of Xpresso, and at
    least I am not aware of any builtin methods that would return the 
    ``DescID`` of a ``GvPort`` in a more sane way.

    This solution is especially lazy, a solution less prone to errors
    would be to iterate over the description of the ``GvNode`` and see which
    combination of ``m, s, u`` is in there.

        node (``c4d.modules.graphview.GvNode``): The node of the port.
        port (``c4d.modules.graphview.GvPort``): The port to get the DescID for.
        ``tuple[int]`` or ``None``: The resolved DescID.
    # The fragments (DescLevels) of the DescID of the port. The problem is
    # that all methods always return an integer-
    m, s, u = port.GetMainID(), port.GetSubID(), port.GetUserID()

    # Now we are just trying to access the node and see if it raises an
    # (attribute) error. If so, we just try the next combination.

    # There are no user data DescLevels below 1.
    if u > 0:
            node[(m, s, u)]
            # It is a user data DescID.
            return (m, s, u)
        except AttributeError as e:

        node[(m, s)]
        # It is a dynamic description DescID.
        return (m, s)
    except AttributeError as e:

        # It is a static description DescID.
        return s
    except AttributeError as e:

    return None

def main():
    """Entry point.
    # This example is for a Xpresso GraphView instance, since I do not
    # have access to RedShift. I did use two constant nodes and a math 
    # node as an example scene.
    if not op or not op.GetTag(c4d.Texpresso):

    tag = op.GetTag(c4d.Texpresso)
    master = tag.GetNodeMaster()
    root = master.GetRoot()

    if not root:

    nodes = root.GetChildren()
    if not nodes:

    # I just took the first top-level node as the node to disconnect, 
    # which was one of the constant nodes connected to the math node.
    out_node = nodes[0]

    # Go over all output ports in our node to disconnect/remove.
    for out_port in out_node.GetOutPorts():
        # Get all input ports the current output port is connected to.
        connected_ports = out_port.GetDestination()
        # Severe all connections from our output port.  
        # Let Cinema catch up.
        # This one of the nastier parts. We will have to unwind the
        # DescID the output port has been build for. See the 
        # respective function for details.
        out_did = get_port_descid(out_node, out_port)
        # We couldn't resolve the DescID properly.
        if out_did is None:
        # Now we are just going over all input ports, get the DescID
        # they are pointing at and write the value from our output_node
        # to the input_node with these two DescIDs.
        for in_port in connected_ports:
            in_node = in_port.GetNode()
            in_did = (in_port.GetMainID(), in_port.GetSubID())
            in_did = get_port_descid(in_node, in_port)
            if in_did is not None:
                in_node[in_did] = out_node[out_did]

if __name__=='__main__':



I did not really test the user data stuff, I just included it, since I knew you are going to need it. But looking at my code now, the user data stuff does not make much sense. It should probably be node[(m, u)] or node[(s, u)]to test for user data ids (probably the first one). User data DescIDs follow the form ID_USERDATA, x, so for example 700, 1 for the first element. You have to poke around a little bit to find out what is what, but my guess would be node[(m, u)].

If you keep running into errors, you should try the description stuff I mentioned in the function docstring instead. The approach of the function is not the safest 😉

PS: You also do not need the line in_did = (in_port.GetMainID(), in_port.GetSubID()), this is just some garbage I forgot to delete before I realised that I was going to need a dedicated function for this 😉


The original code yields image 1:
Screen Shot 2020-05-31 at 5.13.22 AM.png
m, u yields image 2:
Screen Shot 2020-05-31 at 5.14.23 AM.png
s, u yields image 3:
Screen Shot 2020-05-31 at 5.15.05 AM.png
It doesn't look like any of the actual User Data Values (3 of which are colour) are coming through. Here are images of the node and the UD:
Screen Shot 2020-05-31 at 5.18.21 AM.png
Screen Shot 2020-05-31 at 5.18.46 AM.png
Neither m,u or s,u causes the actual User Data to transfer to the nodes before the User Data node gets deleted. Is there something I am missing?


I actually meant doing that inside the get_port_descid function. However, I just did it for you and found out that for user data DescID elements the port returns some gibberish for m, s, u like for example 20000000 1000 -1 for a port for the first user data element for a null (we would at least expect 700 and 1 to pop up in there).

The problem is that ports for user data elements and the DescID they are being build for always have been a bit weird (see GvNode.AddPort). To build a port for the first user data element of a node, we would initialise it with the DescID (700, 5, 1) (the weird part being the 5, which is the integer for the symbol DTYPE_SUBCONTAINER). The other problem is that ports do not really expose the element they point at to the outside world.

I am afraid that you will have to wait for MAXON to shed some light on the topic, but I would not hold my breath for them coming up with a solution. It might very well be the case that you cannot infer the DescID for ports pointing at user data elements.


Cool. I will try a different approach. Thanks for all your help on this, zipit. 🙂

I tried inputting the User Data directly into a RS port using Python and this code:

import c4d

def main():

    obj = op.GetObject()
    neon_col_INPUT = obj[c4d.ID_USERDATA,834]

    # List: Spline, Colour, Power, Gas, Blend.
    spline_UD = {1: 618}

    for item in spline_UD:
        rs_mat = doc.SearchObject ("S" + str (item) + " Gas")
        rs_tag = rs_mat.GetTag(c4d.Ttexture)
        rs_mat = rs_tag.GetMaterial()
        outputNode = rs_mat[c4d.REDSHIFT_GRAPH_NODES]
        gvMaster = outputNode.GetNodeMaster()
        gvRoot = gvMaster.GetRoot()

        colour = obj[c4d.ID_USERDATA,spline_UD[item]]
        print colour

        power = obj[c4d.ID_USERDATA,619]
        gas = obj[c4d.ID_USERDATA,65]
        blend = obj[c4d.ID_USERDATA,66]

        currentNode = gvRoot.GetDown()
        while currentNode is not None:
            if currentNode.GetName() == "RS Material":
                RSMaterial[c4d.REDSHIFT_SHADER_MATERIAL_EMISSION_COLOR] = colour

Now my code causes C4D to hang. Can you help?

I figured out a way to get this to work. They key is separating the User Data out of the RS XPresso node but still maintaining a connection to this node through a regular XPresso node. Cinema won't let me drag Redshift nodes from the RS XPresso window to the C4D XPresso window. Nor can I drag them from the AM.

The solution is to delete the User Data from the RS XPresso window, paste it into a new C4D Xpresso window, then use Set Driven (Absolute) on the RS nodes I need what is essentially double access to. Cinema then automatically creates a new XPresso node, which I then cut the contents from and paste them into my UD Xpresso node.

My only question is what is the difference between Set Driven (Absolute) and Set Driven (Relative)? Does it make a difference? Thanks.


sorry, I did not see your replies. But I cannot help you as I do neither have access to Redshift nor am very fluent when it comes to Cinemas features.


@Swinn said in Redshift deleting using old information:

My only question is what is the difference between Set Driven (Absolute) and Set Driven (Relative)? Does it make a difference?

Both setups add a Range Mapper node. In case of 'Relative', this range mapper creates an offset. See the online help.

Thanks, PluginStudent! 🙂


your question is sometimes not obvious 😄
Even with the scene it's a bit compicated.

What i can say about your code is that you should be more defensive in your code. Always check the value before continue.

For example what if the object is not found ? You should continue to the next item or stop ?

for item in spline_UD:
        rs_mat = doc.SearchObject ("S" + str (item) + " Gas")
        if rs_mat is None:
            # Because we don't have object to continue, we iterate to the next item.