Setting the name of a maxon.GraphNode via Python
-
Hi,
I happily admit, I suck with the maxon node interface.
Still, I achieved most of what I needed. But what seemed to me like the most trivial part, I seem not to be able to accomplish.
I would like to set the name of a (true)maxon.GraphNode(similar to the user clicking the node title and renaming it).
I found this attributemaxon.NODE.BASE.NAME, but I'm not really sure, where to use it.Any help would be much appreciated.
Thanks in advance,
Andreas -
Hey Andreas, hope everything is fine on your end !

Regarding name you can achieve that by calling GraphNode.SetValue with
maxon.NODE.BASE.NAME.
Find bellow an example that set the name of all the selected nodes to "New Name"import c4d import maxon def main(): # Retrieve the selected BaseMaterial mat = doc.GetActiveMaterial() if mat is None: raise ValueError("There is no selected BaseMaterial") # Retrieve the reference of the material as a node material. nodeMaterial = mat.GetNodeMaterialReference() if nodeMaterial is None: raise ValueError("Cannot retrieve node material reference") # Retrieve the current node space Id nodespaceId = c4d.GetActiveNodeSpaceId() # Retrieve the Nimbus reference for a specific node space nimbusRef = mat.GetNimbusRef(nodespaceId) if nimbusRef is None: raise ValueError("Cannot retrieve the nimbus ref for that node space") # Retrieve the graph corresponding to that node space. graph = nimbusRef.GetGraph() if graph is None: raise ValueError("Cannot retrieve the graph of this nimbus ref") # Get the root of the GraphNode root = graph.GetRoot() # Get all selected node # To modify a graph, modification must be done inside a transaction. After # modifications are done, the transaction must be committed. with graph.BeginTransaction() as transaction: for selectedNode in maxon.GraphModelHelper.GetSelectedNodes(graph, maxon.NODE_KIND.NODE): # There is currently an issue affecting some datatype like string, Id, InternedId # So when you set such a datatype it is mandatory to copy the value first to a new variable since SetValue will move the data # Do no use stringValue after SetValue have been called, its data may be gone due to the issue stringValue = maxon.String("New Name") selectedNode.SetValue(maxon.NODE.BASE.NAME, stringValue) print(selectedNode) transaction.Commit() # Pushes an update event to Cinema 4D c4d.EventAdd() if __name__ == "__main__": main()I would also really advice you to take a look at Open source wrapper for Octane/Redshift/Arnold in Cinema 4D you will probably find it handy and is also a great resource to learn the nodes API!
Have a nice weekend.
Cheers,
Maxime. -
Hey Maxime,
thanks for the quick answer.
Actually I thought, I had tried SetValue() with that ID. But either I did something wrong or I tried something else... anyway, thanks.
Just checked: Yes, I did something wrong. I stupidly just passed a string instead of a maxon.String. With the latter it works, not that I doubted your proposal.Maybe would be good, if SetValue() could throw an error, if a wrong type gets passed instead of just doing nothing.
Also thanks for the pointer to Dunhou's project, I was already aware. Nice project! And indeed I peeked into it regarding some Arnold peculiarities...
Cheers,
Andreas