Load valume issue

i’m trying to load volume in python scriptable module script

code :[success, loadedVolumeNode] = slicer.util.loadVolume(path, returnNode=True)

error :

Traceback (most recent call last):
File “”, line 1, in
File “C:/Anand Work/PythonInterfacer.py”, line 9, in
[success, loadedVolumeNode] = slicer.util.loadVolume(path, returnNode=True)
File “C:\Program Files\Slicer 4.8.1\bin\Python\slicer\util.py”, line 377, in loadVolume
return loadNodeFromFile(filename, filetype, properties, returnNode)
File “C:\Program Files\Slicer 4.8.1\bin\Python\slicer\util.py”, line 306, in loadNodeFromFile
success = app.coreIOManager().loadNodes(filetype, properties)
ValueError: Could not find matching overload for given arguments:
(‘VolumeFile’, {‘fileName’: ‘C:\Anand Work\Sft.nrrd’})
The following slots are available:
loadNodes(qSlicerIO::IOFileType fileType, qSlicerIO::IOProperties parameters, vtkCollection loadedNodes) -> bool
loadNodes(qSlicerIO::IOFileType fileType, qSlicerIO::IOProperties parameters) -> bool
loadNodes(qSlicerIO::IOFileType fileType, qSlicerIO::IOProperties parameters, vtkCollection loadedNodes) -> bool
loadNodes(qSlicerIO::IOFileType fileType, qSlicerIO::IOProperties parameters) -> bool

Most likely the problem is that your path contains special characters (\A and \S, note that \ is an escape character). You can use any of these syntaxes instead:

  • r‘C:\Anand Work\Sft.nrrd’ => r prefix specifies raw string, \ is not interpreted as escape character in these strings
  • ‘C:\\Anand Work\\Sft.nrrd’ => double backslash encodes backslash
  • ‘C:/Anand Work/Sft.nrrd’ => forward slashes can be use instead of backslashes