Install extension module in built Slicer

Hi all
I’m having trouble installing an extension module in the built Slicer. Here is my situation:

  • Slicer build was successful.

  • I separately built the source code of the extension module from a Git repository, following the Developer guide for extesion, and it was successful.

  • My current directory structure is as follows:

C:\D\S                             %slicer source
C:\D\SD                            %slicer build
C:\D\SlicerIGSIO                   %extesion source
C:\D\SlicerIGSIO-D                 %extesion build
C:\D\SlicerIGSIO-D\lib\Slicer-5.5
C:\D\SlicerIGT
C:\D\SlicerIGT-D
C:\D\SlicerOpenIGTLink
C:\D\SlicerOpenIGTLink-D

In this situation, how can I make Slicer recognize modules like SlicerIGSIO-D, SlicerIGT-D and ETC ?

*(following option A) I try to find ‘SlicerWithMyExtension’ following the Developer guide for extesion but I can’t

*(following option B) Moreover, I try to add the path to ‘Application setting’ but I could not find ‘qt-scripted-modules’ in ‘C:\D\SlicerIGSIO-D\lib\Slicer-5.5’ instruted in Developer guide

Should the extension module be included in the Slicer build process, or can it be separately built and then included?

The shell script below is and example of what I use when working with an extension that includes multiple c++ and python shared and loadable modules. This is for mac, but something similar should work on windows.

SLICER_BUILD=/opt/sr/Slicer-build
LIB_PATH=$(pwd)/inner-build/lib/Slicer-5.3

${SLICER_BUILD}/Slicer $* \
  --additional-module-paths \
    ${LIB_PATH}/cli-modules ${LIB_PATH}/qt-loadable-modules ${LIB_PATH}/qt-scripted-modules
1 Like

When I am debugging multiple extensions with third-party libraries, I combine the AdditionalLauncherSettings.ini files from each of the extensions into a single one, and launch Slicer/VisualStudio with that file (--launcher-additional-settings GeneratedAdditionalSettings.ini).

I created a python script to combine the files (copied here), but you can copy and paste to merge the ini together manually.

1 Like

Thank you for kind reply!

Then, is it correct that I need to make the following steps every time I edit the code in the extension module?

  1. Edit somthing in extension
  2. build extension
  3. make ini from python
  4. build slicer

Am I right ?

If it is right, could I ask about your development environment? (e.g., cmake, vscode or visual studio)

I try to use vscode because it it easy to make settings.json for cmake and running python

You shouldn’t need to rebuild Slicer if you’re only editing the extension.

The ini also probably won’t need to be changed unless you

  • a) Add a new extension that you want to use.
    or
  • b) Modify the inclusion of ThirdParty libraries of an extension in CMake.

I use CMake and Visual Studio for compiling Slicer on Windows (see Windows — 3D Slicer documentation).

I am sorry for such a basic question.

I made .ini file follow your python code it is amazing !!

Then, I try to do command like this

C:\D\SD\Slicer-build>Slicer.exe --VisualStudio --launcher-additional-settings C:\D\SD\GeneratedSuperAdditionalLauncherSettings.ini

Is this right ?
After the visual studio come up I try to build slicer then, turn on it again
but I cannot find any changes …

Hi Kyle Sunderland
I tried this also

C:\D\SD\Slicer-build>slicer --launcher-additional-settings C:\D\S\GeneratedSuperAdditionalLauncherSettings.ini

There is no error but nothing was changed , I cannot find extension modules in my slicer.

This is my .ini file. Is there something wrong ?

[General]
additionalpathvariables = PYTHONPATH

[LibraryPaths]
1\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/cli-modules/Debug
2\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Debug
3\path = C:/D/SlicerIGSIO-D/lib/Slicer-5.5/Debug
4\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/cli-modules/Debug
5\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Debug
6\path = C:/D/SlicerOpenIGTLink-D/lib/Slicer-5.5/Debug
7\path = C:/D/SlicerOpenIGTLink-D/OpenIGTLink-buildC:/D/SlicerOpenIGTLink-D/OpenIGTLink-build/bin/DebugC:/D/SlicerOpenIGTLink-D/binC:/D/SlicerOpenIGTLink-D/bin/Debug
8\path = C:/D/SlicerOpenIGTLink-D/OpenIGTLinkIO-buildC:/D/SlicerOpenIGTLink-D/OpenIGTLinkIO-build/bin/DebugC:/D/SlicerOpenIGTLink-D/binC:/D/SlicerOpenIGTLink-D/bin/Debug
size = 8

[Paths]
1\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/cli-modules/Debug
2\path = C:/D/SlicerIGSIO-D/inner-build/bin/Debug
3\path = C:/D/SlicerIGSIO-D/bin/Debug
4\path = C:/D/SlicerIGSIO-D/VP9/
5\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/cli-modules/Debug
6\path = C:/D/SlicerOpenIGTLink-D/inner-build/bin/Debug
7\path = C:/D/SlicerOpenIGTLink-D/bin/Debug
size = 7

[EnvironmentVariables]

[PYTHONPATH]
1\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/qt-scripted-modules
2\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Debug
3\path = C:/D/SlicerIGSIO-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Python
4\path = C:/D/SlicerIGSIO-D/lib/Slicer-5.5/Debug
5\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/qt-scripted-modules
6\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Debug
7\path = C:/D/SlicerOpenIGTLink-D/inner-build/lib/Slicer-5.5/qt-loadable-modules/Python
8\path = C:/D/SlicerOpenIGTLink-D/lib/Slicer-5.5/Debug
size = 8

You also still need to include --additional-module-paths when launching Slicer, pointing to the qt-loadable-modules/Debug, qt-scripted-modules and cli-modules/Debug for each of the extensions.

You mean… in commend line?

I really appreciate if you provide to me the example of your commend line and .ini
Then I can follow you

Yes, in command line, something like:

"C:/d/s/S4W/Slicer-build/Slicer.exe" --launcher-additional-settings "C:d/s/GeneratedSuperAdditionalLauncherSettings.ini --additional-module-paths "C:\d\s\SIGSIOW\inner-build\lib\Slicer-5.5\qt-loadable-modules\RelWithDebInfo" "C:\d\s\SOIGTLW\inner-build\lib\Slicer-5.5\qt-loadable-modules\RelWithDebInfo" "C:\d\s\SOIGTLW\inner-build\lib\Slicer-5.5\qt-scripted-modules" "C:\d\s\SIGTW\lib\Slicer-5.5\qt-loadable-modules\RelWithDebInfo" "C:\d\s\SIGTW\lib\Slicer-5.5\qt-scripted-modules"

Thank you Kyle !

I sovled the problem!

Then I made a python code the to run Slicer with .ini setting
automatically consider additional path setting

import subprocess
import configparser

paths = []
config = configparser.ConfigParser()
config.read('C:/D3/S/GeneratedSuperAdditionalLauncherSettings.ini')

# Check if the 'Paths' section exists in the INI file
if 'Paths' in config:
    paths_section = config['PYTHONPATH']

    # Get all the keys in the 'Paths' section
    path_keys = paths_section.keys()

    # Iterate through the keys and print the corresponding values
    for key in path_keys:
        if key != 'size':  # Exclude the 'size' key
            path_value = paths_section[key]
            paths.append(path_value)

command = [
    "C:/D3/SR/Slicer-build/Slicer.exe",
    
    "--launcher-additional-settings",
    "C:/D3/S/GeneratedSuperAdditionalLauncherSettings.ini",
    
    "--additional-module-paths",
]+paths

subprocess.run(command)
1 Like