CLI script to screen capture 3D View

Could some one share the solution for creating 3d views of volume and segmentation using cli commands.

I tried one example to execute the command line_loopfolders_volumerendering.py using

/Applications/Slicer.app/Contents/MacOS/Slicer --no-splash --no-main-window --python-script "/Users/3D-Slicer-Scripts/command line_loopfolders_volumerendering.py"  -f /Users/data/in

and got AttributeError: 'NoneType' object has no attribute 'threeDWidget'

Environment - Slicer 5.6.2, macOS 14.5

It seems to run fine without --no-main-window but i wanted to run this as command line script.

It seems to error out with layoutManager

layoutManager = slicer.app.layoutManager()
threeDWidget = layoutManager.threeDWidget(0)

Layout manager is provided by the application main window. If you don’t have a main window then you don’t have a layout manager. You can fix the error by removing --no-main-window.

If you need a full example, check out the script that generates this Auto3DSeg segmentation model catalog page.

Thank you for providing the script. I successfully ran the segmentation process. Is it possible to generate 3D view images using a batch CLI command with screencapture? I understand that screencapture requires the layout manager to generate images, which typically needs the main window. Since this is not feasible with batch CLI commands running in a Unix terminal, is there an alternative workaround for this?

You can do everything with commands on the terminal. You can pass Python commands as command-line arguments or you can put all the commands in a .py file and execute that from the command-line. If popping up of a GUI window is bothering you then you can use a dockerized version of Slicer.

1 Like

Thank you for providing the docker reference. I managed to get it working as suggested and generated screen captured images and video of it.

1 Like