Solved Node Method IsValid() Throws ValueError


I'm trying to write a script that modify the selected nodes only if the node is an RS Texture node. And the way I can know if its an RS Texture Node is if it has the tex0 attribute (see below)

My logic is something like this:

rs_texture_node = node.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0")

if rs_texture_node.IsValid():
       # Do something here

It works if the node selected is a texture node but throws a ValueError: no target to copy for '<net.maxon.graph.interface.graphmodel>' if its otherwise.

Which I don't get. It's either the node/port is valid or not. Why throw an error?

Hello @bentraje,

Thank you for reaching out to us. This is an error which is raised in the C++ part of our Python API (and not just the Python frameworks trampoline code). It happens when something is meant to be wrapped into a CPyObject (so that Python can deal with it) and the something is a null pointer.

Without executable code it will be hard for us to replicate your problem. As always, you can send code to us privately via sdk_support(at)maxon(dot)net. In the meantime you could try if you have better luck with maxon.Data.IsNullValue() which we have added with 2023.0.0. It tests for a reference being the empty reference, i.e., what you want to do here. maxon.GraphNode is an instance of maxon.Data. So, you would have to do this isNull: bool = rs_texture_node.IsNullValue(). When you search for garbage, e.g., FindChild("blahblah"), the value should be true.


MAXON SDK Specialist


Thanks for response.

RE: added 2023.
I'm still at R25 so I can't use that route unfortunately.

Anyhow, I just settled on the GetId() which works the same way. It's just that doing a split method is bit awkward.

if node.GetId().split("@")[0] == 'texturesampler':

        texPort = node.GetInputs().FindChild("com.redshift3d.redshift4c4d.nodes.core.texturesampler.tex0")
        # do something more for the texPort

Hi @bentraje, as Ferdinand said without more code is hard to help you. Happy that you solved it, I just wanted to warn you that your code will not work anymore in newer version, since in 2023.0 everything that return a maxon.Id, does return a maxon.Id and not anymore a python string. So if yo uwant to be future proof, use if str(node.GetId()).split("@")[0] == 'texturesampler':



Gotcha. Thanks for the heads up!