# Calling scripted cli module Output

**URL:** <https://discourse.slicer.org/t/calling-scripted-cli-module-output/36962>\
**Category:** Development\
**Created:** [June 23, 2024, 5:45am UTC](https://discourse.slicer.org/t/calling-scripted-cli-module-output/36962 "2024-06-23T05:45:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fqzhice](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@fqzhice](https://discourse.slicer.org/u/fqzhice)\
**Post date:** [June 23, 2024, 5:45am UTC](https://discourse.slicer.org/t/calling-scripted-cli-module-output/36962/1 "2024-06-23T05:45:06Z")

</div>

I create a scripted cli module according to SlicerPythonCLIExample, and set print in .py file.

```auto
#!/usr/bin/env python-real `
import os  
print("call vessel segment!")`

```

Then in a cpp file , it is called as below:

```auto
PythonQt::init();
PythonQtObjectPtr context = PythonQt::self()->getMainModule();
context.evalScript(QString(
    "slicer.cli.run(slicer.modules.ctaseg, None, None)\n"
));

```

But there is no output string in console window. just

```auto
Found CommandLine Module, target is C:/PilotImage/Release/Slicer-build/lib/Slicer-5.4/cli-modules/Release/CTASeg.py
ModuleType: CommandLineModule
No input data assigned to "Input Volume"

```

Does this script run correctly？ or the input volume is necessary

Thanks

---

<div class="post-metadata">

**Author:** ![fqzhice](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@fqzhice](https://discourse.slicer.org/u/fqzhice)\
**Post date:** [June 23, 2024, 6:55am UTC](https://discourse.slicer.org/t/calling-scripted-cli-module-output/36962/2 "2024-06-23T06:55:04Z")

</div>

Later

```
vtkMRMLNode* dummyNode = qSlicerApplication::application()->mrmlScene()->GetFirstNodeByClass("vtkMRMLScalarVolumeNode");

PythonQt::init();
PythonQtObjectPtr context = PythonQt::self()->getMainModule();
context.evalScript(QString(
    "param={}\n"
    "param['inputVolume']=%1\n"
    "slicer.cli.runSync(slicer.modules.ctaseg, None, parameters=param)\n"
).arg(dummyNode->GetID()));

```

it says name ‘vtkMRMLScalarVolumeNode1’ is not defined

---

<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:** [June 23, 2024, 10:22pm UTC](https://discourse.slicer.org/t/calling-scripted-cli-module-output/36962/3 "2024-06-23T22:22:07Z")

</div>

Process output is logged into the application log and also available in the CLI module node.

If you develop in C++ then you can use the C++ API (no need to call out to Python).

---

<div class="post-metadata">

**Author:** ![fqzhice](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@fqzhice](https://discourse.slicer.org/u/fqzhice)\
**Post date:** [June 24, 2024, 1:20am UTC](https://discourse.slicer.org/t/calling-scripted-cli-module-output/36962/4 "2024-06-24T01:20:15Z")

</div>

I try to call the custom AI-module in python script.  
Now I cant find the generated result image, so i set an print to check if it works. it seems fails .  
I try to find in log later.  
Thanks

---

<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:** [June 24, 2024, 2:04am UTC](https://discourse.slicer.org/t/calling-scripted-cli-module-output/36962/5 "2024-06-24T02:04:14Z")

</div>

We have many modules that segment images by using xuatom AI models. I would recommend to start from a similar module.

Does the segmentation tool use nn-unet, monai, or just pyrorch directly?

---

<div class="post-metadata">

**Author:** ![fqzhice](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@fqzhice](https://discourse.slicer.org/u/fqzhice)\
**Post date:** [June 24, 2024, 8:50am UTC](https://discourse.slicer.org/t/calling-scripted-cli-module-output/36962/6 "2024-06-24T08:50:24Z")

</div>

The module is developped by other guy and i was required to make an integration. Maybe is some unet module.  
I just call “slicer.util.launchConsoleProcess” to implement it

Thanks very much

---

<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:** [June 24, 2024, 10:53am UTC](https://discourse.slicer.org/t/calling-scripted-cli-module-output/36962/7 "2024-06-24T10:53:11Z")

</div>

If it is nnunet then I would recommend to use [GitHub - gaudot/SlicerDentalSegmentator: 3D Slicer extension for fully-automatic segmentation of CT and CBCT dental volumes.](https://github.com/gaudot/SlicerDentalSegmentator) extension as an example, and if anything else then the [GitHub - lassoan/SlicerMONAIAuto3DSeg: Extension for 3D Slicer for running MONAI Auto3DSeg models](https://github.com/lassoan/SlicerMONAIAuto3DSeg) extension.
