Operating system: Windows Latest version
Slicer version: 4.8.1
Expected behavior: The Slicer program should start running and open the visual file, however it doesn’t do so.
Actual behavior: The Slicer program does not open the file when it is passed through an external Python Command
I am writing a Python (3.6) program which opens an image file directly into 3D Slicer starting from the filepath of the desired image.
When I run the command with the full file path 3D slicer reacts correctly and opens my file:
The line of code which works is the following
subprocess.Popen(['C:/Program Files/Slicer 4.8.1/Slicer.exe', '--python-code' , 'slicer.util.loadVolume("C:/Users/Documents/Untitled Folder/sampledata3D.tif")'] , stdout = PIPE, stderr= PIPE)
However as soon as I try to pass a variable containing the path of the file, and not the direct path it stops working. This is an example of how the program needs 3D Slicer to open the file:
subprocess.Popen(['C:/Program Files/Slicer 4.8.1/Slicer.exe', '--python-code' , 'slicer.util.loadVolume( " %s " )' % openfile ] , stdout = PIPE, stderr= PIPE)
However it opens 3D Slicer but in this case does not directly open the file. I have tried all the possible combinations but it doesn’t work!
This is another format I attempted which doesn’t work:
subprocess.Popen(['C:/Program Files/Slicer 4.8.1/Slicer.exe', '--python-code' , "slicer.util.loadVolume( self.openfilename )"] , stdout = PIPE, stderr= PIPE)
Can anyone help me with this?
It is essential for my project and if this doesn’t work I will have to look for another viewer to support my software!