# SlicerPythonCLIExample **Repository Path**: anxingle/SlicerPythonCLIExample ## Basic Information - **Project Name**: SlicerPythonCLIExample - **Description**: No description available - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-10-31 - **Last Updated**: 2023-10-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SlicerPythonCLIExample Example extension for 3D Slicer that demonstrates how to make a Python script available as a CLI module Let's assume you have a [BlurImage.py](BlurImage/BlurImage.py) Python script that you can run from the command line as `python BlurImage.py input.nrrd 5.0 output.nrrd`. You can make this Python script available in Slicer using a nice auto-generated GUI just by adding a description of input and output parameters in a [Slicer Execution Model](https://www.slicer.org/wiki/Documentation/Nightly/Developers/SlicerExecutionModel) module descriptor XML file: [BlurImage.xml](BlurImage/BlurImage.xml). Once `BlurImage` folder is added to additional module paths (or the extension package is installed), "Blur Image" module will show up in the module list (in Filtering / Denoising category) and can be used in Slicer as any other module. ![Auto-generated graphical user interface for Python script](BlurImageAutoGeneratedGUI.png) The script can be executed from any other module, [the same way as other CLI modules](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#Running_a_CLI_from_Python). Example: ```python import SampleData inputImage = SampleData.downloadSample('MRHead') outputImage = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLScalarVolumeNode', inputImage.GetName()+' blurred') param = {} param["inputVolume"] = inputImage.GetID() param["outputVolume"] = outputImage.GetID() param["sigma"] = 3.0 slicer.cli.runSync(slicer.modules.blurimage, parameters=param) ```