# Adding node reference

**URL:** <https://discourse.slicer.org/t/adding-node-reference/22817>\
**Category:** Development\
**Created:** [April 4, 2022, 2:57pm UTC](https://discourse.slicer.org/t/adding-node-reference/22817 "2022-04-04T14:57:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [April 4, 2022, 2:57pm UTC](https://discourse.slicer.org/t/adding-node-reference/22817/1 "2022-04-04T14:57:25Z")

</div>

Hi,

I’m trying to understand how can I use `SetAndObserveNodeReferenceID()`.

For example I have a model node and a markups node.  
The markups node is some kind of a “child” node of a model and and it is going to be located under a model node within subject hierarchy module.

I would like to keep relative position (relative to the model node) of markups node to be constant.  
Thus whenever model/markups node gets transformed I need to apply the same transform to the markups/model node.

I understand that I can use `SetAndObserveNodeReferenceID("MyRole", "markups node Id")` but I dont understand where to process the events?  
I have some experience of working with vtk observers and vtk callback command and I guess there should be some method/function that I need to implement…

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [April 5, 2022, 8:45am UTC](https://discourse.slicer.org/t/adding-node-reference/22817/2 "2022-04-05T08:45:17Z")

</div>

You could try to investigste this usecase:

> <https://github.com/SlicerHeart/SlicerHeart/blob/42b75a6184b31d785eaef61ff695f4de99834356/BafflePlanner/BafflePlanner.py>

Source:

> **[Build software better, together](https://github.com/search?l=Python&q=SetAndObserveNodeReferenceID&type=Code)**
>
> GitHub is where people build software. More than 73 million people use GitHub to discover, fork, and contribute to over 200 million projects.

I would interested in knowing how did you solve it at the end.

Thank you

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [April 5, 2022, 1:08pm UTC](https://discourse.slicer.org/t/adding-node-reference/22817/3 "2022-04-05T13:08:46Z")

</div>

Thank you for the example,

For now I decided to postpone this and use `AddNodeReferenceID` without observing any events.

Probably later I will try to refer to the problem once again.

---

<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:** [April 7, 2022, 12:38pm UTC](https://discourse.slicer.org/t/adding-node-reference/22817/4 "2022-04-07T12:38:30Z")

</div>

Moving nodes together is very easy, just set the same parent transform to all of them. If you want to have a fixed relative transform between them then add the relative transform as a transform node, use the commom transform node as parent, and set this transform node as parent for the second model node.

`SomeNode.SetAndOvserveNodeReferenceID(otherNode)` will notify the `SomeNode` if `otherNode` is modified. No other classes will be notified. If you want to observe changes in `otherNode` outside of `SomeNode` then you can add an observer directly using `AddObserver`.
