# Custom MRML Node with Python

**URL:** <https://discourse.slicer.org/t/custom-mrml-node-with-python/27633>\
**Category:** Support\
**Tags:** mrml\
**Created:** [February 4, 2023, 4:57pm UTC](https://discourse.slicer.org/t/custom-mrml-node-with-python/27633 "2023-02-04T16:57:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kleingeo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kleingeo/32/6772_2.png) [@kleingeo](https://discourse.slicer.org/u/kleingeo)\
**Post date:** [February 4, 2023, 4:57pm UTC](https://discourse.slicer.org/t/custom-mrml-node-with-python/27633/1 "2023-02-04T16:57:34Z")

</div>

Is there a way to define a custom MRML node that can be used with a module developed with the python backend?

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [February 9, 2023, 10:05am UTC](https://discourse.slicer.org/t/custom-mrml-node-with-python/27633/2 "2023-02-09T10:05:18Z")

</div>

As far as I know it is not possible to subclass C++ classes in Python. What we do in cases like yours is that we use `vtkMRMLScriptedModuleNode`, a generic class for Python modules, set the module name accordingly, and use its attributes to store data (instead of properties you’d define in a C++ class).

Also it may help looking into this:

> **[Slicer/Base/Python/slicer/parameterNodeWrapper at main · Slicer/Slicer](https://github.com/Slicer/Slicer/tree/main/Base/Python/slicer/parameterNodeWrapper)**
>
> main/Base/Python/slicer/parameterNodeWrapper

---

<div class="post-metadata">

**Author:** ![kleingeo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kleingeo/32/6772_2.png) [@kleingeo](https://discourse.slicer.org/u/kleingeo)\
**Post date:** [February 9, 2023, 4:48pm UTC](https://discourse.slicer.org/t/custom-mrml-node-with-python/27633/3 "2023-02-09T16:48:06Z")

</div>

I am using the `vtkMRMLScriptedModuleNode` to build a module. I am loading/creating multiple `vtkMRMLMarkupsFiducialNodes`, but I also need to track other information per node. The current implementation of `parameterNodeWrapper` does not integrate well with the current `vtkMRMLNodes`.

Another option is to connect the different `qt` objects that track the information directly to the `vtkMRMLMarkupsFiducialNodes`, which seems cumbersome if possible.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [February 10, 2023, 9:56am UTC](https://discourse.slicer.org/t/custom-mrml-node-with-python/27633/4 "2023-02-10T09:56:17Z")

</div>

It would help if you described your use case in mode detail.

> [@kleingeo](#):
>
> also need to track other information per node

You can add attributes in the nodes themselves.

---

<div class="post-metadata">

**Author:** ![kleingeo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/kleingeo/32/6772_2.png) [@kleingeo](https://discourse.slicer.org/u/kleingeo)\
**Post date:** [February 13, 2023, 4:07pm UTC](https://discourse.slicer.org/t/custom-mrml-node-with-python/27633/5 "2023-02-13T16:07:57Z")

</div>

> [@cpinter](#):
>
> It would help if you described your use case in mode detail.

I have a python module where many `vtkMRMLMarkupsFiducialNodes` are loaded and created and features need to be tracked. What I would like to do is define a new class for the `vtkMRMLMarkupsFiducialNodes` where the features I care about are defined as parameters of the object. The idea is for a user to use radio buttons to change which feature from a few options, so I would also like to have this class have better integration with the radio buttons themselves so when different `vtkMRMLMarkupsFiducialNodes` are chosen the radio button selection moves with them.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [February 13, 2023, 6:13pm UTC](https://discourse.slicer.org/t/custom-mrml-node-with-python/27633/6 "2023-02-13T18:13:02Z")

</div>

Based on this vague description it still seems a good idea to use the Attributes of the nodes you need to store properties for.

If you insist you can subclass nodes in C++.
