Hi, I always have the problem with the working directory of Slicer.
when I use
nrrd.write(filename,data)
I have no idea where my filename.nrrd is stored.
And everytime I try to load a model or file to Slicer, the relative path(./directory) won’t work. So I have to use the full path. Is there a solution to this problem?
slicer.modules.sampledata.path: path of a scripted module (in this example: Sample Data module)
You can also pass any folder name to Slicer via the command-line. For example:
"c:\Program Files\Slicer 4.10.1\Slicer.exe" --python-code "myDataDir='%cd%';loadVolume(myDataDir+'vol.nrd'); (do some processing here...); saveNode(someNode,myDataDir+'processed.nrrd')"
Hi, thanks for the answer. This is a very clear explanation. But I still have some problem here.
In my scripted module, I got an array and I want to save it as a .nrrd file. I used nrrd.write but I still can’t find my file. I tried to look it up in slicer.modules.sampledata.path, but it’s not there. Where is it or how can I load this file to Slicer?
If you have a numpy array and you want to show it as an image in Slicer then you don’t need to write it to file. You can directly write it to a volume node using slicer.util.updateVolumeFromArray.
if you want to write a temporary file, you can use slicer.app.temporaryPath, for example: