# Rename nodes with python script

**URL:** <https://discourse.slicer.org/t/rename-nodes-with-python-script/33385>\
**Category:** Support\
**Tags:** python\
**Created:** [December 14, 2023, 12:44am UTC](https://discourse.slicer.org/t/rename-nodes-with-python-script/33385 "2023-12-14T00:44:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JamesM](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@JamesM](https://discourse.slicer.org/u/JamesM)\
**Post date:** [December 14, 2023, 12:44am UTC](https://discourse.slicer.org/t/rename-nodes-with-python-script/33385/1 "2023-12-14T00:44:10Z")

</div>

Hello. I have a question. Currently, I am loading more than 10 MRI series per patient, each acquired on different dates, and measuring volumes. However, the node names are inconsistent, and I would like to rename them in chronological order using the date information from DICOM files. I believe I can achieve this by accessing the Python script. Could you provide how to approach this? I’ve also searched through Python script repositories but couldn’t find a solution.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/d/4daf40905c5c5703b7ea735bda0d670255d53912.png)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [December 14, 2023, 12:51am UTC](https://discourse.slicer.org/t/rename-nodes-with-python-script/33385/2 "2023-12-14T00:51:50Z")

</div>

You can do something like this example:

[https://slicer.readthedocs.io/en/latest/developer\_guide/script\_repository.html#batch-processing](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#batch-processing)

Iterate through the studies for the patient and query the StudyData using the `slicer.dicomDatabase.fileValue` method to get the data to sort the data. You can load the series you want and use SetName to provide a consistent convention. You may need some special case code to deal with the variability in clinical naming conventions.

---

<div class="post-metadata">

**Author:** ![JamesM](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@JamesM](https://discourse.slicer.org/u/JamesM)\
**Post date:** [December 14, 2023, 1:29am UTC](https://discourse.slicer.org/t/rename-nodes-with-python-script/33385/3 "2023-12-14T01:29:40Z")

</div>

Thanks for the quick response. I have one more question. Can I perform 3D Slicer tasks using Spyder with Python? I want to use Spyder instead of the Python console.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [December 15, 2023, 1:08pm UTC](https://discourse.slicer.org/t/rename-nodes-with-python-script/33385/4 "2023-12-15T13:08:35Z")

</div>

People have done things like that - you can search for it. I didn’t find it worth the effort but if you have good luck please report back.
