How to display the `slicer.vtkMRMLTextNode` in slice view or pyhon interactor?

How to display or print the slicer.vtkMRMLTextNode's Text in slice view or pyhon interactor?

Here is the documentation for the vtkMRMLTextNode class: Slicer: vtkMRMLTextNode Class Reference

textNodeName = 'My Text Node'
textNode = slicer.util.getNode(textNodeName)
print(textNode.GetText())
2 Likes

Thanks, but how to export/import the node?
I want to edit it in external editor.

Do you mean that you did not actually want to view the text? Or you mean that what @mikebind described works well and now you would like to write this text to file?

Please describe your end goal because if we give solutions to your low-level tasks that may not lead to solving your high-level task in an optimal way.

image
I want to save this Node, but get “false”

Text nodes with very short text (<250 characters) default to saving in the MRML scene file rather than in their own files, meaning that they do not get storage nodes by default. I think it is the lack of storage node which leads to saveNode failing. You can force a text node to have a storage node like this

tx = getNode('Text')
tx.SetForceCreateStorageNode(1)
# Now this will work
saveNode(tx, r"text333.txt")
2 Likes

and howto import this txt file?

https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.loadText

2 Likes


谢谢老师, 太棒了. :+1: :+1:

1 Like