# Iterate over slicer modules

**URL:** <https://discourse.slicer.org/t/iterate-over-slicer-modules/215>\
**Category:** Development\
**Created:** [April 27, 2017, 6:15pm UTC](https://discourse.slicer.org/t/iterate-over-slicer-modules/215 "2017-04-27T18:15:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mirclem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mirclem/32/3356_2.png) [@mirclem](https://discourse.slicer.org/u/mirclem)\
**Post date:** [April 27, 2017, 6:15pm UTC](https://discourse.slicer.org/t/iterate-over-slicer-modules/215/1 "2017-04-27T18:15:54Z")

</div>

Hello,

I am working on creating a program to get all the modules loaded in Slicer. I know I can access the list with all the module names, I also know that I can access a module by hard typing the module name like “slicer.modules.modelmaker”. But is there a way to access a module with a variable or a string?

The first command I tried was slicer.modules[variable] but it can’t work because modules is a namespace.

Thanks,  
Clément

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [April 27, 2017, 6:18pm UTC](https://discourse.slicer.org/t/iterate-over-slicer-modules/215/2 "2017-04-27T18:18:05Z")

</div>

> [@mirclem](#):
>
> But is there a way to access a module with a variable or a string?

`getattr(slicer.modules,'units')`

---

<div class="post-metadata">

**Author:** ![mirclem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mirclem/32/3356_2.png) [@mirclem](https://discourse.slicer.org/u/mirclem)\
**Post date:** [April 27, 2017, 6:23pm UTC](https://discourse.slicer.org/t/iterate-over-slicer-modules/215/3 "2017-04-27T18:23:15Z")

</div>

Hum, sometimes when you don’t find what you want, it’s nice to get back to python basics.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![Johan\_Andruejol](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/johan_andruejol/32/3639_2.png) [@Johan\_Andruejol](https://discourse.slicer.org/u/Johan_Andruejol)\
**Post date:** [April 27, 2017, 6:29pm UTC](https://discourse.slicer.org/t/iterate-over-slicer-modules/215/4 "2017-04-27T18:29:44Z")

</div>

Clement,

You could also use the slicer util method [getModule()](https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/util.py#L467).

Johan

---

<div class="post-metadata">

**Author:** ![mirclem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mirclem/32/3356_2.png) [@mirclem](https://discourse.slicer.org/u/mirclem)\
**Post date:** [May 1, 2017, 8:46pm UTC](https://discourse.slicer.org/t/iterate-over-slicer-modules/215/5 "2017-05-01T20:46:03Z")

</div>

Based on the work done before, I was able to access the module, then the widget and the currentCLInode. So, I can get the parameters names, flags, types. But, I can’t find the way to access the current value corresponding to a parameter.  
I saw there is a function ‘WriteParameterFile’ which is able to access the value and match it with the key but the [source code](https://github.com/Slicer/Slicer/blob/9e7de7256691782a2650a312313d47aafa31c4a2/Libs/MRML/CLI/vtkMRMLCommandLineModuleNode.cxx#L1001-L1013) can’t help me.

---

<div class="post-metadata">

**Author:** ![Johan\_Andruejol](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/johan_andruejol/32/3639_2.png) [@Johan\_Andruejol](https://discourse.slicer.org/u/Johan_Andruejol)\
**Post date:** [May 1, 2017, 9:04pm UTC](https://discourse.slicer.org/t/iterate-over-slicer-modules/215/6 "2017-05-01T21:04:51Z")

</div>

Hey Clement,

Did you look at [GetParameterAsString()](https://github.com/Slicer/Slicer/blob/9e7de7256691782a2650a312313d47aafa31c4a2/Libs/MRML/CLI/vtkMRMLCommandLineModuleNode.h#L250) ?

Johan

---

<div class="post-metadata">

**Author:** ![mirclem](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mirclem/32/3356_2.png) [@mirclem](https://discourse.slicer.org/u/mirclem)\
**Post date:** [May 1, 2017, 9:08pm UTC](https://discourse.slicer.org/t/iterate-over-slicer-modules/215/7 "2017-05-01T21:08:43Z")

</div>

Thank you so much Johan!

---

<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:** [May 15, 2017, 11:52pm UTC](https://discourse.slicer.org/t/iterate-over-slicer-modules/215/8 "2017-05-15T23:52:51Z")

</div>

A post was split to a new topic: [Access color table in CLI module](https://discourse.slicer.org/t/access-color-table-in-cli-module/318)
