# Getting pointer on module's logic and open/show the logic widget

**URL:** <https://discourse.slicer.org/t/getting-pointer-on-modules-logic-and-open-show-the-logic-widget/28654>\
**Category:** Development\
**Created:** [March 29, 2023, 2:23pm UTC](https://discourse.slicer.org/t/getting-pointer-on-modules-logic-and-open-show-the-logic-widget/28654 "2023-03-29T14:23:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adeguet1](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@adeguet1](https://discourse.slicer.org/u/adeguet1)\
**Post date:** [March 29, 2023, 2:23pm UTC](https://discourse.slicer.org/t/getting-pointer-on-modules-logic-and-open-show-the-logic-widget/28654/1 "2023-03-29T14:23:04Z")

</div>

In python, we can do: `slicer.util.getModuleLogic(name)` and `getModuleLogic`. Is there an equivalent in C++? For example, when loading a MRML scene, in the UpdateScene callback, I’d like to make sure a module exists and has been properly loaded. I would also like to know if the GUI for that module is shown.

Since it would be in the Node::UpdateScene, is there a path from the scene pointer to find the application’s logic and from there find the module’s logic? Or, is there a registry accessible via a static methods to all the loaded modules?

---

<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:** [March 29, 2023, 2:40pm UTC](https://discourse.slicer.org/t/getting-pointer-on-modules-logic-and-open-show-the-logic-widget/28654/2 "2023-03-29T14:40:43Z")

</div>

> [@adeguet1](#):
>
> In python, we can do: `slicer.util.getModuleLogic(name)` and `getModuleLogic`. Is there an equivalent in C++?

You can get a module’s logic from any other module’s logic using the [GetModuleLogic(moduleName)](https://apidocs.slicer.org/main/classvtkSlicerModuleLogic.html#a7d7ca329e0cc60869ed8a20829eaa9ae) method. From any GUI class, you can use the application’s [moduleLogic(moduleName)](https://apidocs.slicer.org/main/classqSlicerCoreApplication.html#a9aa6380c45c7dae28e933af109d550bf) method.

> [@adeguet1](#):
>
> I’d like to make sure a module exists and has been properly loaded

If your module depends on a module (the module class returns the list of dependencies in the `dependencies()` method) then tou don’t need to check if that module exists. Slicer would not initialize your module if any of the dependencies were missing.

> [@adeguet1](#):
>
> I would also like to know if the GUI for that module is shown.

Whether a module has a GUI, has it been created, or shown yet is a private business of that module. In general, a module should not directly access or manipulate another module’s GUI in any way. Instead, your module can modify the MRML scene and other modules can observe those changes. You can also call methods in any other module’s logic.

Why would you need to know if another module’s GUI is shown?

> [@adeguet1](#):
>
> Since it would be in the Node::UpdateScene, is there a path from the scene pointer to find the application’s logic and from there find the module’s logic?

Nodes are only for data storage, so you don’t initiate any module logic operations from there. Instead, your module logic can observe scene changes and perform operations in response.
