Module from console with arguments

Hi everybody,

I run a specific module using the terminal like this: Slicer.exe --python-code selectModule('MyModule').

Now, the code of the module take arguments (-t), and I try to run the module just adding: Slicer.exe --python-code selectModule('MyModule') -t 44

But it doenst work, the argument is not taken (‘NoneType’), so its possible to run a module with arguments in this way? and which is the correct syntax?

Thanks a lot,
Lucas.

1 Like

Is it a scripted CLI module or a scripted Loadable module?

Hi Andras,

Its just a scripted loadable module.

Thanks+

You can then simply list all the commands you want to launch at startup, separated by semicolons. If you want to submit many commands or you would like to avoid messing with proper quotation marks and indentation then you can specify a Python script filename to launch at startup.

If you want to interact with the application after it is started (load more data, remove data, etc) then you can use Slicer’s REST API.

There is a Python package - slicerio - that you can pip install very easily into any Python environment that allows you to start Slicer, load data, view data, export data, etc. using a few simple Python function calls. If you find that some features are missing then feel free to add them and submit pull requests.

Hi Andras, I tried like this, but it didnt work:

Slicer.exe --python-code selectModule('MyModule'); -t 20

In this case “t” is an argument which modify a specific action of the module. The use the semicolons is correct in this case?

Thanks+

You can use --python-code to specify all parameters and actions by multiple Python commands, separated by semicolons, quoted if contains spaces. For example:

Slicer.exe --python-code "selectModule('SampleData'); getModuleGui('SampleData').setCategoryVisible('BuiltIn', False)"

Alternatively, you can use --python-script to specify a launcher script and set each additional parameter as a separate command-line argument. You can parse the arguments using Python argparse as usual. For example:

Slicer.exe --python-script path/to/BatchStructureSetConversion.py --input-folder input/folder/path --output-folder output/folder/path

You can find a complete example of a script that is launched like this here.