How to use TotalSegmentator from Script with "--no-main-window" option

Hi everyone,

I am new 3DSlicer user. I was able to develop my own script which can use TotalSegmentator automatically. But I would like to run it without graphical interface.

The script is working well with graphical interface, but when I use the command “–no-splash --no-main-window”, the program returns me an error because it requires the main-window.

This is the error:

Traceback (most recent call last):

  • File “”, line 5, in *
  • File “”, line 26, in *
  • File “/usr/local/apps/3DSlicer/5.2.1/bin/Python/slicer/util.py”, line 1156, in selectModule*
  • selector = moduleSelector()*
  • File “/usr/local/apps/3DSlicer/5.2.1/bin/Python/slicer/util.py”, line 1141, in moduleSelector*
  • raise RuntimeError(“Could not find main window”)*
    RuntimeError: Could not find main window

Could I have any help with this? It is possible to run the module without the main-window?

Thanks in advance,
-Sergio

If you want to run headless, you can just use the original tool. GitHub - wasserth/TotalSegmentator: Tool for robust segmentation of 104 important anatomical structures in CT images

In that case, you would probably want to install TotalSegmentator in a separate Python instance on your machine as described here and run your script independently.

But you could also write a script that calls the logic of the TotalSegmentator extension in 3D Slicer which will in turn, perform a TotalSegmentator run.

Thank you very much for your quick response.

Yes, I considered also that way. However, I am using the “DicomRtImportExportPlugin” at the end of the segmentation to export the results to DICOM files (Images and RTstructures).

So, what I did is to create an script that is working well when I call it using the following command:

Slicer --python-script “/full/path/to/myscript.py” --no-splash

But it is not working when I use the next one:

Slicer --python-script “/full/path/to/myscript.py” --no-splash --no-main-window

Because it seems that TotalSegmentator module requires “main-window”.

Is it possible to run this without main-window?

Thanks,
-Sergio

This thread should help:

Hi, sir, could you give an example of a script that calls the logic of TotalSegmentator extension?

I know how to do it. I forgot to import it.