# Issue with Including Scripted Module in Custom Slicer-Based Application

**URL:** <https://discourse.slicer.org/t/issue-with-including-scripted-module-in-custom-slicer-based-application/43408>\
**Category:** Development\
**Tags:** extensions-manager, python, module\
**Created:** [June 18, 2025, 2:02pm UTC](https://discourse.slicer.org/t/issue-with-including-scripted-module-in-custom-slicer-based-application/43408 "2025-06-18T14:02:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![software](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/software/32/79627_2.png) [@software](https://discourse.slicer.org/u/software)\
**Post date:** [June 18, 2025, 2:02pm UTC](https://discourse.slicer.org/t/issue-with-including-scripted-module-in-custom-slicer-based-application/43408/1 "2025-06-18T14:02:09Z")

</div>

Hi all,

I’ve developed a custom Slicer-based application and included a custom scripted module called `HemisphereVolumeCalculator`  
In my top-level `CMakeLists.txt`, I’ve added it using:

```cmake
set(Slicer_EXTENSION_SOURCE_DIRS
  ${Safe_SOURCE_DIR}/Modules/Scripted/HemisphereVolumeCalculator
)

```

The module runs fine when I add its path through the **application settings → Additional Module Paths**. However, after building my application from the generated `Safe.sln` (on Windows), the module does **not** appear in the application interface by default.

### ❓ Questions:

1. Is there anything else I need to do beyond setting `Slicer_EXTENSION_SOURCE_DIRS` to ensure the module gets built and bundled?
2. How can I confirm whether the module was recognized or included during the build?
3. Are there any additional flags (e.g., `Slicer_QTSCRIPTEDMODULES_ENABLED`) that I need to set manually?

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [June 18, 2025, 2:13pm UTC](https://discourse.slicer.org/t/issue-with-including-scripted-module-in-custom-slicer-based-application/43408/2 "2025-06-18T14:13:58Z")

</div>

Does the folder `Modules/Scripted/HemisphereVolumeCalculator` contains a `CMakeLists` similar to [this one](https://github.com/KitwareMedical/SlicerCustomAppTemplate/blob/main/%7B%7Bcookiecutter.project_name%7D%7D/Modules/Scripted/Home/CMakeLists.txt) ?

> 1. How can I confirm whether the module was recognized or included during the build?

You should see the following output when the inner build is configured:

```auto
[...]
-- --------------------------------------------------
-- Configuring Safe application: SafeApp
-- --------------------------------------------------
...
-- --------------------------------------------------
-- Configuring extension directory: Home
-- Configuring Scripted module: Home
-- --------------------------------------------------
-- Configuring extension directory: HemisphereVolumeCalculator
-- Configuring Scripted module: HemisphereVolumeCalculator
[...]

```

> 1. Are there any additional flags (e.g., `Slicer_QTSCRIPTEDMODULES_ENABLED`) that I need to set manually?

Those are related to the Slicer built-in scripted modules and not the one you are explicitly developing as part of the custom app.

---

<div class="post-metadata">

**Author:** ![software](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/software/32/79627_2.png) [@software](https://discourse.slicer.org/u/software)\
**Post date:** [June 18, 2025, 2:25pm UTC](https://discourse.slicer.org/t/issue-with-including-scripted-module-in-custom-slicer-based-application/43408/3 "2025-06-18T14:25:08Z")

</div>

Thanks for the reply! Here’s how things are currently set up in my custom Slicer app.

This is the relevant part from the **top-level CMakeLists.txt** of my custom application (`Safe`):

```cmake
# Enable Slicer built-in modules
set(Slicer_CLIMODULES_ENABLED
  ResampleDTIVolume # Needed by ResampleScalarVectorDWIVolume
  ResampleScalarVectorDWIVolume # Depends on DiffusionApplications, needed by CropVolume
)

set(Slicer_QTLOADABLEMODULES_ENABLED
)

set(Slicer_QTSCRIPTEDMODULES_ENABLED
)

# Disable Slicer built-in modules
set(Slicer_CLIMODULES_DISABLED
)

set(Slicer_QTLOADABLEMODULES_DISABLED
  SceneViews
  SlicerWelcome
  ViewControllers
)

set(Slicer_QTSCRIPTEDMODULES_DISABLED
  DataProbe
  DMRIInstall
  Endoscopy
  LabelStatistics
  PerformanceTests
  SampleData
  SurfaceToolbox
  VectorToScalarVolume
)

# Enable/Disable Slicer custom modules: To create a new module, use the SlicerExtensionWizard.
set(Slicer_EXTENSION_SOURCE_DIRS
  #${Safe_SOURCE_DIR}/Modules/CLI/MyCLIModule
  #${Safe_SOURCE_DIR}/Modules/Loadable/MyLoadableModule
  ${Safe_SOURCE_DIR}/Modules/Scripted/Home
  ${Safe_SOURCE_DIR}/Modules/Scripted/HemisphereVolumeCalculator
)

```

And this is the `CMakeLists.txt` inside the `HemisphereVolumeCalculator` module directory:

```cmake
#-----------------------------------------------------------------------------
set(MODULE_NAME HemisphereVolumeCalculator)

#-----------------------------------------------------------------------------
slicerMacroBuildScriptedModule(
  NAME ${MODULE_NAME}
  SCRIPTS ${MODULE_NAME}.py
  RESOURCES_DIR Resources/Icons
  WITH_GENERIC_TESTS
)

```

The module is placed correctly under the `Scripted` folder, and I’ve confirmed the paths are valid. But it’s still not showing up in the UI after building the application. Let me know if you see anything I’m missing!

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [June 18, 2025, 2:46pm UTC](https://discourse.slicer.org/t/issue-with-including-scripted-module-in-custom-slicer-based-application/43408/4 "2025-06-18T14:46:28Z")

</div>

After re-configuring & building the project from the top-level, the CMake cache variable `Slicer_EXTENSION_SOURCE_DIRS` set in the inner-build `CMakeCache.txt` (see `<top-level>/Slicer-build/CMakeCache.txt`) should include the path `/path/to/Modules/Scripted/HemisphereVolumeCalculator`.

Could you check this is the case ?

Next, can you check that:

- The text `Configuring Scripted module: HemisphereVolumeCalculator` is displayed when configuring the inner project
- The relevant module files are copied when you force rebuild only the target `CopySlicerPythonScriptFiles` after opening the solution file found in the inner build directory

---

<div class="post-metadata">

**Author:** ![software](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/software/32/79627_2.png) [@software](https://discourse.slicer.org/u/software)\
**Post date:** [June 19, 2025, 8:28am UTC](https://discourse.slicer.org/t/issue-with-including-scripted-module-in-custom-slicer-based-application/43408/5 "2025-06-19T08:28:54Z")

</div>

@jcfr  
Thanks! I just updated the module’s `CMakeLists.txt` according to the one you shared, and after rebuilding, the module now appears in the application  
**Before Update:**

```cmake
#-----------------------------------------------------------------------------
set(MODULE_NAME HemisphereVolumeCalculator)

#-----------------------------------------------------------------------------
slicerMacroBuildScriptedModule(
  NAME ${MODULE_NAME}
  SCRIPTS ${MODULE_NAME}.py
  RESOURCES_DIR Resources/Icons
  WITH_GENERIC_TESTS
)

```

✅ **After Update:**

```cmake
#-----------------------------------------------------------------------------
set(MODULE_NAME HemisphereVolumeCalculator)

#-----------------------------------------------------------------------------
set(MODULE_PYTHON_SCRIPTS
  ${MODULE_NAME}.py
)

#-----------------------------------------------------------------------------
set(MODULE_PYTHON_RESOURCES
  Resources/Icons/${MODULE_NAME}.png
)

#-----------------------------------------------------------------------------
slicerMacroBuildScriptedModule(
  NAME ${MODULE_NAME}
  SCRIPTS ${MODULE_PYTHON_SCRIPTS}
  RESOURCES ${MODULE_PYTHON_RESOURCES}
)

```

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [June 19, 2025, 2:54pm UTC](https://discourse.slicer.org/t/issue-with-including-scripted-module-in-custom-slicer-based-application/43408/7 "2025-06-19T14:54:00Z")

</div>

For future reference, note that the `RESOURCES_DIR` is not a valid argument for the `slicerMacroBuildScriptedModule` CMake macro.

---

<div class="post-metadata">

**Author:** ![software](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/software/32/79627_2.png) [@software](https://discourse.slicer.org/u/software)\
**Post date:** [June 20, 2025, 7:49am UTC](https://discourse.slicer.org/t/issue-with-including-scripted-module-in-custom-slicer-based-application/43408/8 "2025-06-20T07:49:29Z")

</div>

@jcfr  
Okay sir, I see the custom module appears correctly in the application after each build. However, I’m getting an error every time, even though the module is properly packaged.  
Could you please advise what might be causing this issue or how I can debug it?

Thank you!  
Custom build for ‘E:\Safe\build\CMakeFiles\467e983c5e5c61d75f97be2c5e12c91e\Slicer-mkdir.rule;E:\Safe\build\CMakeFiles\467e983c5e5c61d75f97be2c5e12c91e\Slicer-download.rule;E:\Safe\build\CMakeFiles\467e983c5e5c61d75f97be2c5e12c91e\Slicer-update.rule;E:\Safe\build\CMakeFiles\467e983c5e5c61d75f97be2c5e12c91e\Slicer-patch.rule;E:\Safe\build\CMakeFiles\467e983c5e5c61d75f97be2c5e12c91e\Slicer-configure.rule;E:\Safe\build\CMakeFiles\467e983c5e5c61d75f97be2c5e12c91e\Slicer-build.rule;E:\Safe\build\CMakeFiles\467e983c5e5c61d75f97be2c5e12c91e\Slicer-forceconfigure.rule;E:\Safe\build\CMakeFiles\467e983c5e5c61d75f97be2c5e12c91e\Slicer-install.rule;E:\Safe\build\CMakeFiles\a4776f2d8ebb7610c206d34e471bef41\Slicer-complete.rule;E:\Safe\build\CMakeFiles\aa031ac59c12a6e617a2dfdd12069198\Slicer.rule;E:\Safe\build\slicersources-src\CMakeLists.txt’ exited with code 1.
