# Python Script - Export DICOM Tag issue

**URL:** https://discourse.slicer.org/t/python-script-export-dicom-tag-issue/29507
**Category:** Support
**Created:** [May 17, 2023, 2:20pm UTC](https://discourse.slicer.org/t/python-script-export-dicom-tag-issue/29507 "2023-05-17T14:20:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Markb](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@Markb](https://discourse.slicer.org/u/Markb)
#### Post date: [May 17, 2023, 2:20pm UTC](https://discourse.slicer.org/t/python-script-export-dicom-tag-issue/29507/1 "2023-05-17T14:20:33Z")

</div>

Hi all. I have a python script to automate making a bunch of masked data based on a PET and RTStruct file. As there are quite a few segments per study, and I have hundreds of studies, I want to automate this as much as possible. The mask bit works great, but the next stage is exporting the data as a DICOM dataset.

When I do this manually, I would drag the masked data into the parent folder in the Data scene, and right click Export DICOM. I would select an appropriate folder and leave everything else as default, and this works create but as I can only do one at a time, it is slow and prone to human error.

My script is all set up to create the relevant folders etc. and save the nodes, but with the DICOMExportScalarVolume command, it needs the tags. I was hoping to just copy these from the initial PET data, but I’m struggling to find a way to do this. Any direction would be greatly appreciated.

Thank you

---

<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: [May 17, 2023, 9:24pm UTC](https://discourse.slicer.org/t/python-script-export-dicom-tag-issue/29507/2 "2023-05-17T21:24:14Z")

</div>

If you look at the source code there’s a comment with an example of copying tags from a study:

> <https://github.com/Slicer/Slicer/blob/1f99feaa638394effd53b4e14636b28082d6ff8b/Modules/Scripted/DICOMLib/DICOMExportScalarVolume.py#L10>

---

<div class="post-metadata">

### Author: ![Markb](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@Markb](https://discourse.slicer.org/u/Markb)
#### Post date: [May 18, 2023, 10:02am UTC](https://discourse.slicer.org/t/python-script-export-dicom-tag-issue/29507/3 "2023-05-18T10:02:18Z")

</div>

Thank you Steve. I saw that bit of the code commented out and labelled TODO and assumed it was just a bit that wasn’t working yet. I don’t really understand what it is doing at the moment, but I’ll spend some time with it and see if I can digest it.

---

<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: [May 18, 2023, 1:22pm UTC](https://discourse.slicer.org/t/python-script-export-dicom-tag-issue/29507/4 "2023-05-18T13:22:38Z")

</div>

That’s good that you can investigate and report back what you find. The `tags` argument should allow you to populate the headers with the needed values to make valid (or at least usable) dicom files. Creating valid files for various modalities is tricky, and you may need to check them with a tool like [`dciodvfy`](https://dclunie.com/dicom3tools/dciodvfy.html) and make further tweaks, perhaps with pydicom, to make them work for your intended use.
