# CLI script to screen capture 3D View

**URL:** <https://discourse.slicer.org/t/cli-script-to-screen-capture-3d-view/38401>\
**Category:** Development\
**Tags:** segmentation, python\
**Created:** [September 16, 2024, 6:47pm UTC](https://discourse.slicer.org/t/cli-script-to-screen-capture-3d-view/38401 "2024-09-16T18:47:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jithendra](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jithendra/32/7658_2.png) [@Jithendra](https://discourse.slicer.org/u/Jithendra)\
**Post date:** [September 16, 2024, 6:47pm UTC](https://discourse.slicer.org/t/cli-script-to-screen-capture-3d-view/38401/1 "2024-09-16T18:47:46Z")

</div>

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](https://github.com/jzeyl/3D-Slicer-Scripts/blob/master/command%20line_loopfolders_volumerendering.py) using

```auto
/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.

---

<div class="post-metadata">

**Author:** ![Jithendra](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jithendra/32/7658_2.png) [@Jithendra](https://discourse.slicer.org/u/Jithendra)\
**Post date:** [September 16, 2024, 6:54pm UTC](https://discourse.slicer.org/t/cli-script-to-screen-capture-3d-view/38401/2 "2024-09-16T18:54:08Z")

</div>

It seems to error out with layoutManager

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

```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 16, 2024, 11:12pm UTC](https://discourse.slicer.org/t/cli-script-to-screen-capture-3d-view/38401/3 "2024-09-16T23:12:59Z")

</div>

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](https://github.com/lassoan/SlicerMONAIAuto3DSeg/blob/e37d719f14a8d72692287d132547995672d3aba2/MONAIAuto3DSeg/MONAIAuto3DSeg.py#L1612-L1684) that generates this [Auto3DSeg segmentation model catalog page](https://github.com/lassoan/SlicerMONAIAuto3DSeg/releases/tag/ModelsTestResults).

---

<div class="post-metadata">

**Author:** ![Jithendra](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jithendra/32/7658_2.png) [@Jithendra](https://discourse.slicer.org/u/Jithendra)\
**Post date:** [September 17, 2024, 6:06am UTC](https://discourse.slicer.org/t/cli-script-to-screen-capture-3d-view/38401/4 "2024-09-17T06:06:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 17, 2024, 2:58pm UTC](https://discourse.slicer.org/t/cli-script-to-screen-capture-3d-view/38401/5 "2024-09-17T14:58:49Z")

</div>

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](https://github.com/pieper/SlicerDockers).

---

<div class="post-metadata">

**Author:** ![Jithendra](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jithendra/32/7658_2.png) [@Jithendra](https://discourse.slicer.org/u/Jithendra)\
**Post date:** [September 19, 2024, 11:34am UTC](https://discourse.slicer.org/t/cli-script-to-screen-capture-3d-view/38401/6 "2024-09-19T11:34:29Z")

</div>

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