# Use orient scaler volume in python interactor for batch processing

**URL:** <https://discourse.slicer.org/t/use-orient-scaler-volume-in-python-interactor-for-batch-processing/26096>\
**Category:** Development\
**Created:** [November 6, 2022, 11:44pm UTC](https://discourse.slicer.org/t/use-orient-scaler-volume-in-python-interactor-for-batch-processing/26096 "2022-11-06T23:44:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hourieh](https://avatars.discourse-cdn.com/v4/letter/h/5e9695/32.png) [@hourieh](https://discourse.slicer.org/u/hourieh)\
**Post date:** [November 6, 2022, 11:44pm UTC](https://discourse.slicer.org/t/use-orient-scaler-volume-in-python-interactor-for-batch-processing/26096/1 "2022-11-06T23:44:45Z")

</div>

Operating system:windows  
Slicer version:5.0.3  
Expected behavior:i want to orient my .nii volumes to axial dicom volumes in python code but I can not find any example of that. please help me!  
Actual behavior:

---

<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:** [November 7, 2022, 5:00am UTC](https://discourse.slicer.org/t/use-orient-scaler-volume-in-python-interactor-for-batch-processing/26096/2 "2022-11-07T05:00:16Z")

</div>

You can find [example of how to export a volume to DICOM using Python in the script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#export-a-volume-to-dicom-file-format).

---

<div class="post-metadata">

**Author:** ![hourieh](https://avatars.discourse-cdn.com/v4/letter/h/5e9695/32.png) [@hourieh](https://discourse.slicer.org/u/hourieh)\
**Post date:** [November 7, 2022, 7:28am UTC](https://discourse.slicer.org/t/use-orient-scaler-volume-in-python-interactor-for-batch-processing/26096/3 "2022-11-07T07:28:15Z")

</div>

Thank you for your quick response.  
i used this code but it export my volume to saggital slices and I want axial slice…  
i wrote this for changing to axial but not working and I got the same result as before:

volumeNode = slicer.util.loadVolume(r"F:\arshad\payannameh\New folder (3)\MRI\ADNI\_002\_S\_0413\_MR\_MPR\_\_GradWarp\_\_B1\_Correction\_\_N3\_Br\_20070821171714281\_S22557\_I69527.nii", {"name ": ‘alzheimerMRI’})

axialSliceToRas=vtk.vtkMatrix3x3()  
sliceNode = getNode(“ADNI\_002\_S\_0413\_MR\_MPR\_\_GradWarp\_\_B1\_Correction\_\_N3\_Br\_20070821171714281\_S22557\_I69527”)  
red\_logic = slicer.app.layoutManager().sliceWidget(“Red”).sliceLogic()  
red\_cn = red\_logic.GetSliceCompositeNode()  
red\_logic.GetSliceCompositeNode().SetBackgroundVolumeID(sliceNode.GetID())

outputFolder = r"F:\arshad\payannameh\New folder (3)\axial\New folder"

slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)  
patientItemID = shNode.CreateSubjectItem(shNode.GetSceneItemID(), “test patient”)  
studyItemID = shNode.CreateStudyItem(patientItemID, “test study”)  
volumeShItemID = shNode.GetItemByDataNode(sliceNode)  
shNode.SetItemParent(volumeShItemID, studyItemID)

import DICOMScalarVolumePlugin  
exporter = DICOMScalarVolumePlugin.DICOMScalarVolumePluginClass()  
exportables = exporter.examineForExport(volumeShItemID)  
for exp in exportables:  
exp.directory = outputFolder  
exp.setTag(‘PatientID’, “test patient”)  
exp.setTag(‘StudyID’, “test study”)

exporter.export(exportables)

In addition, can I use orient scaler volume module to achieve my goal?  
if yes how to use it in python interaction?

---

<div class="post-metadata">

**Author:** ![hourieh](https://avatars.discourse-cdn.com/v4/letter/h/5e9695/32.png) [@hourieh](https://discourse.slicer.org/u/hourieh)\
**Post date:** [November 7, 2022, 12:49pm UTC](https://discourse.slicer.org/t/use-orient-scaler-volume-in-python-interactor-for-batch-processing/26096/4 "2022-11-07T12:49:17Z")

</div>

I was able to find the solution with your help:

```
volumeNode = slicer.util.loadVolume(inputdir)

slicer.util.selectModule('OrientScalarVolume')
orient_scalar = slicer.modules.orientscalarvolume

outputVolume = slicer.vtkMRMLScalarVolumeNode()
slicer.mrmlScene.AddNode(outputVolume)
outputVolume.CreateDefaultDisplayNodes()
outputVolume.SetName("output_orient")

parametersOrient = {}
parametersOrient["inputVolume1"] = volumeNode
parametersOrient["outputVolume"] = outputVolume
parametersOrient["orientation"] = 'Axial'

orientNode = None
orientNode = slicer.cli.runSync(orient_scalar, None, parametersOrient)        
shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
patientItemID = shNode.CreateSubjectItem(shNode.GetSceneItemID(), "test patient")
studyItemID = shNode.CreateStudyItem(patientItemID, "test study")
volumeShItemID = shNode.GetItemByDataNode(outputVolume)
shNode.SetItemParent(volumeShItemID, studyItemID)

import DICOMScalarVolumePlugin
exporter = DICOMScalarVolumePlugin.DICOMScalarVolumePluginClass()
exportables = exporter.examineForExport(volumeShItemID)
for exp in exportables:
    exp.directory = outputdir
    exp.setTag('PatientID', "test patient")
    exp.setTag('StudyID', "test study")

exporter.export(exportables)

```
