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

**URL:** <https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535>\
**Category:** Development\
**Tags:** python\
**Created:** [March 16, 2022, 10:08am UTC](https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535 "2022-03-16T10:08:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [March 16, 2022, 10:08am UTC](https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535/1 "2022-03-16T10:08:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [March 16, 2022, 3:22pm UTC](https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535/2 "2022-03-16T15:22:14Z")

</div>

Here is the documentation for the vtkMRMLTextNode class: [Slicer: vtkMRMLTextNode Class Reference](https://apidocs.slicer.org/master/classvtkMRMLTextNode.html)

```auto
textNodeName = 'My Text Node'
textNode = slicer.util.getNode(textNodeName)
print(textNode.GetText())

```

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [March 16, 2022, 8:41pm UTC](https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535/3 "2022-03-16T20:41:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 16, 2022, 9:18pm UTC](https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535/4 "2022-03-16T21:18:39Z")

</div>

> [@jumbojing](#):
>
> Thanks, but how to export/import the node?

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.

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [March 16, 2022, 10:28pm UTC](https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535/5 "2022-03-16T22:28:21Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/2/f253bd36f119d55d6fc1aa32e247fe70331ea8f7.png)  
I want to save this Node, but get “false”

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [March 16, 2022, 10:38pm UTC](https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535/6 "2022-03-16T22:38:41Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [March 16, 2022, 10:40pm UTC](https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535/7 "2022-03-16T22:40:21Z")

</div>

and howto import this txt file?

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [March 16, 2022, 10:43pm UTC](https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535/8 "2022-03-16T22:43:54Z")

</div>

[https://slicer.readthedocs.io/en/latest/developer\_guide/slicer.html#slicer.util.loadText](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.loadText)

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [March 16, 2022, 10:54pm UTC](https://discourse.slicer.org/t/how-to-display-the-slicer-vtkmrmltextnode-in-slice-view-or-pyhon-interactor/22535/9 "2022-03-16T22:54:54Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/3/534a9fda6c780d8d5d9623641555c1951866cec5.png)  
谢谢老师, 太棒了. 👍 👍
