# Exporting Dicom programatically

**URL:** <https://discourse.slicer.org/t/exporting-dicom-programatically/972>\
**Category:** Development\
**Tags:** dicom\
**Created:** [August 30, 2017, 9:53pm UTC](https://discourse.slicer.org/t/exporting-dicom-programatically/972 "2017-08-30T21:53:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmtg](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@mmtg](https://discourse.slicer.org/u/mmtg)\
**Post date:** [August 30, 2017, 9:53pm UTC](https://discourse.slicer.org/t/exporting-dicom-programatically/972/1 "2017-08-30T21:53:31Z")

</div>

Hello everyone,

This is a question I asked a while ago and it was resolved. However, that was with a much older version and my script no longer works with the newer versions of slicer that have a different subjecthierarchy organization.

I decided to try and remake it for newer versions. However I am having issues understanding how it works, especially since I am not a strong programmer and very unfamiliar with how the SubjectHierarchy works on the backend.

I started off looking here:

> <https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py#L516>

specifically the line:  
volumeNode = shNode.GetItemDataNode(exportable.subjectHierarchyItemID)

So the volumeNode it gets is the same as if I were to do

volumeNode = getNode(‘_Some\_name_’)

what I don’t understand is how to get the item ID’s quickly. The first step is

shn = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)

and when I look at that I see that there are ID’s. But I don’t see/ know how to get the ID for a volume node. From what I can tell, it seems that all the methods associated with shn need you to know the itemID ahead of time. I am assuming there is some other method to get the ID for a volumeNode but I don’t know where to look.

I am sure it’s right in front of me but spent some time and couldn’t see where. I appreciate any help

---

<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:** [August 30, 2017, 10:06pm UTC](https://discourse.slicer.org/t/exporting-dicom-programatically/972/2 "2017-08-30T22:06:30Z")

</div>

The method you are looking for is [GetItemByDataNode](http://apidocs.slicer.org/master/classvtkMRMLSubjectHierarchyNode.html#a05a31b3a075a4bc08abf3997bcc8f562).

Subject hierarchy usage examples:

- [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Subject\_hierarchy](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Subject_hierarchy)
- [https://github.com/Slicer/Slicer/blob/master/Applications/SlicerApp/Testing/Python/SubjectHierarchyGenericSelfTest.py](https://github.com/Slicer/Slicer/blob/master/Applications/SlicerApp/Testing/Python/SubjectHierarchyGenericSelfTest.py)

In general, use the [API documentation](http://apidocs.slicer.org/master/) and examples in [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository) and in [Slicer core self-tests and Python scripted modules](https://github.com/Slicer/Slicer/tree/master/).
