Batch Processing Error - convertedPath

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 :

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):
      # 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


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.