AddNewNodeByClass: basename does not increment


From my understanding, AddNewNodeByClass accepts a basename that would increment with a suffix on repeat calls. For example:

slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelNode", "M")

should yield model nodes with names M, M_1, M_2…

I could not observe this naming pattern.

I’m probably missing something here. Can someone point to the right usage for this expectation?

Thank you.

AddNewNodeByClass accepts a name that is set to the node, but sets it exactly as specified. If you’d like to generate a unique name then utilize slicer.mrmlScene.GenerateUniqueName("…") as part of the string you pass into AddNewNodeByClass. If any documentation is incorrect or unclear, then I’m sure improvements to the API documentation would be welcome.

vtkMRMLScene.h has this note:

/// \note Instead of calling SetName() after creating the node, prefer
/// passing \a nodeBaseName, indeed the method AddNode() ensures that the
/// final node name is unique in the scene by appending a suffix if needed.

It may mean that the unique name is handled by ‘AddNode’, itself called by ‘AddNewNodeByClass’.

Anyway, it’s easy to use ‘GenerateUniqueName’.

Thank you.