# Saving RTSTRUCT Nodes as Nifti Files

**URL:** https://discourse.slicer.org/t/saving-rtstruct-nodes-as-nifti-files/24843
**Category:** Support
**Tags:** python, file-export
**Created:** [August 20, 2022, 7:27am UTC](https://discourse.slicer.org/t/saving-rtstruct-nodes-as-nifti-files/24843 "2022-08-20T07:27:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![enamdar](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@enamdar](https://discourse.slicer.org/u/enamdar)
#### Post date: [August 20, 2022, 7:27am UTC](https://discourse.slicer.org/t/saving-rtstruct-nodes-as-nifti-files/24843/1 "2022-08-20T07:27:14Z")

</div>

Hi everyone.  
I have loaded a patient volume, its segmentation, and the corresponding RTSTURCT.  
I need to save the components of the RTSTRUCT as separate nifti files using the python command line, but I have no idea how I can do that.  
 ![Screenshot from 2022-08-19 23-00-23](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/7/27357fb69cc330cb9dea27bba4f9d9fb587c2f51.png)

---

<div class="post-metadata">

### Author: ![enamdar](https://avatars.discourse-cdn.com/v4/letter/e/8c91f0/32.png) [@enamdar](https://discourse.slicer.org/u/enamdar)
#### Post date: [August 24, 2022, 8:52pm UTC](https://discourse.slicer.org/t/saving-rtstruct-nodes-as-nifti-files/24843/2 "2022-08-24T20:52:48Z")

</div>

I figured it out.  
First, a for loop was needed over the visible segment ids.  
Then the following two commands to export the segments:

> slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsToLabelmapNode(segmentationNode, segIds, labelmapVolumeNode, referenceVolumeNode)

> slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsBinaryLabelmapRepresentationToFiles(dst\_patient\_dir, segmentationNode, segIds, “seg.nii.gz”, True)

Exporting the volume was the most straightforward part. slicer.util.exportNode does the job.
