GraphModelInterface.GetNode not worked
-
Hi community,
I notice
GraphModelInterface.GetNode
method seems broken in R2025.0.2, and also theToString()
seems broken too. Is my usage incorrect?Cheers~
DunHoubtw: R2025 tag is missing in forum
import c4d import maxon import typing doc: c4d.documents.BaseDocument # The active document. def main(): for material in doc.GetMaterials(): nodeMaterial: c4d.NodeMaterial = material.GetNodeMaterialReference() if not nodeMaterial.HasSpace("com.redshift3d.redshift4c4d.class.nodespace"): continue graph: maxon.GraphModelRef = nodeMaterial.GetGraph("com.redshift3d.redshift4c4d.class.nodespace") root: maxon.GraphNode = graph.GetViewRoot() spaceContext = root.GetValue(maxon.nodes.NODESPACE.NodeSpaceContext) nodeSpaceId = spaceContext.Get(maxon.nodes.NODESPACE.SPACEID) spaceData = maxon.NodeSpaceHelpersInterface.GetNodeSpaceData(nodeSpaceId) assetId = spaceData.Get(maxon.nodes.NODESPACE.IMAGENODEASSETID) inTexturePortId = spaceData.Get(maxon.nodes.NODESPACE.IMAGENODEPORTS)[1] for node in root.GetInnerNodes(maxon.NODE_KIND.NODE, False): assetId: maxon.Id = node.GetValue("net.maxon.node.attribute.assetid")[0] if assetId != maxon.Id("com.redshift3d.redshift4c4d.nodes.core.texturesampler"): continue pathPort: maxon.GraphNode = graph.GetNode(node.GetPath() + '>' + str(inTexturePortId)) url: str | None = pathPort.GetPortValue() print (f"{pathPort}: {url}") if __name__ == "__main__": main()
-
Hi thanks for contacting us, since you are calling node.GetPath() then use the + operator. This will use the + operator from the NodePath which add \ at the beginning so its not a bug but the expected behavior since it add a new folder.
In your case if you really want to build the string then you need to first build a string and then construct a NodePath from this string like so:
pathPort: maxon.GraphNode = graph.GetNode(maxon.NodePath(str(node.GetPath()) + '<' + str(inTexturePortId)))
Cheers,
Maxime. -
Hi @m_adam ,
Thanks for your reply, it worked well.
But I still have some doubts about the usage of Node Path, such as how to calculate the port through NodePath instead of concatenating strings (which can easily lead to misoperation).
There are few examples and answers for NodePath on the forum, and it seems that people rarely use it. Do you have any insights on this, or in other words, what usage scenarios do you think NodePath is more suitable for.
Cheers~
DunHou