# Batch Processing Error - convertedPath

**URL:** <https://discourse.slicer.org/t/batch-processing-error-convertedpath/31720>\
**Category:** Development\
**Tags:** segmentation, python\
**Created:** [September 14, 2023, 3:52pm UTC](https://discourse.slicer.org/t/batch-processing-error-convertedpath/31720 "2023-09-14T15:52:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![trussel1](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/trussel1/32/67529_2.png) [@trussel1](https://discourse.slicer.org/u/trussel1)\
**Post date:** [September 14, 2023, 3:52pm UTC](https://discourse.slicer.org/t/batch-processing-error-convertedpath/31720/1 "2023-09-14T15:52:19Z")

</div>

Operating system: Windows  
Slicer version: 5.40

I have a general understanding of 3D Slicer and have been using for a few years now. I now have a project with a large data set and want to start using Python to segment data using batch processing.

I have referenced the Script repository along with other recommend material previously mentioned in other posts but I am getting an error stating that “NameError: name ‘convertedPath’ is not defined”. Can someone help me troubleshoot this ?

_Snippet of Code_ :

```auto
import os
import unittest
import vtk, qt, ctk, slicer
from slicer.ScriptedLoadableModule import *
from DICOMLib import DICOMUtils
import logging

db = slicer.dicomDatabase
patients = db.patients()
patientCount = 0
for patient in patients:
  patientCount += 1
  print(f"Patient {patient} ({patientCount} of {len(patients)})")
  for study in db.studiesForPatient(patient):
    print(f"Study {study}")
    for series in db.seriesForStudy(study):
      print(f"Series {series}")
      temporaryDir = qt.QTemporaryDir()
      for instanceUID in db.instancesForSeries(series):
        qt.QFile.copy(db.fileForInstance(instanceUID), f"{temporaryDir.path()}/{instanceUID}.dcm")
      patientID = slicer.dicomDatabase.instanceValue(instanceUID, '0010,0020')
      outputPath = os.path.join(convertedPath, patientID, study, series, "BatchResult")
      if not os.path.exists(outputPath):
        os.makedirs(outputPath)
      # do an operation here that processes the series into the outputPath

masterVolumeNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLScalarVolumeNode")

# Create segmentation
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)

```

Best,  
Ty

---

<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:** [September 14, 2023, 6:33pm UTC](https://discourse.slicer.org/t/batch-processing-error-convertedpath/31720/2 "2023-09-14T18:33:49Z")

</div>

> [@trussel1](#):
>
> “NameError: name ‘convertedPath’ is not defined”. Can someone help me troubleshoot this ?

The example script is just a skeleton. You’ll need to have something like `convertedPath = "/tmp/output"` as a place to store the converted data.
