# Select vtkMRMLModelNode on mouse click

**URL:** <https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348>\
**Category:** Development\
**Created:** [June 28, 2019, 2:41am UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348 "2019-06-28T02:41:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacbaum](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/zacbaum/32/7166_2.png) [@zacbaum](https://discourse.slicer.org/u/zacbaum)\
**Post date:** [June 28, 2019, 2:41am UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/1 "2019-06-28T02:41:43Z")

</div>

Hello,

I am trying to implement a mouse interaction wherein the user clicks on a model from the 3D viewer and the model which was clicked is made available so that it can be modified in some way (such as colour change, etc.). I was able to find a similar example [here](https://lorensen.github.io/VTKExamples/site/Python/Interaction/HighlightPickedActor/) from the VTK examples page but have not been able to reproduce the behaviour with vtkMRMLModelNodes within Slicer.

Any help is appreciated.

---

<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:** [June 28, 2019, 11:07pm UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/2 "2019-06-28T23:07:56Z")

</div>

We plan to add a feature like this within a couple of months, but until then you can use something like what is implemented [here](https://github.com/Slicer/Slicer/commit/f1b55fc99e948629e8a048c619d685a25ac0ba4d).

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [June 1, 2023, 3:12am UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/3 "2023-06-01T03:12:43Z")

</div>

> [@lassoan](#):
>
> couple of months, but un

Hi Andras,  
Is the modelnode selection function available.

I have a model and selected nodes with using fiducials. Is there a way to left mouse click the fiducial and save that fiducial coordinates. For example if the user has model and selected nodes but the user needs the location of only few control points. is it possible to get the location by only left mouse click on the fiducial.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/e/febb331bb2f9d93128c07deac91ec11ea79506f1.png)

---

<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:** [June 1, 2023, 12:05pm UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/4 "2023-06-01T12:05:56Z")

</div>

This example could be a starting point:  
[https://slicer.readthedocs.io/en/latest/developer\_guide/script\_repository.html#get-a-notification-if-a-markup-control-point-position-is-modified](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#get-a-notification-if-a-markup-control-point-position-is-modified)

I’d probably try to use the `PointEndInteractionEvent` event to get notified about the click, and by getting the active control point index you know which one was clicked.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [June 7, 2023, 4:12am UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/5 "2023-06-07T04:12:36Z")

</div>

> [@cpinter](#):
>
> point index you know which one was clicked.

Hi,  
I am having trouble with connecting mouse click.

How can I attach the mouse click event with this method or may be I am understanding it wrong.

in main process code I have  
markupsNode = slicer.util.getNode(inputFiducial.GetID())  
print(markupsNode)  
markupsNode.AddObserver(slicer.vtkMRMLMarkupsNode.PointEndInteractionEvent, self.onMarkupEndInteraction)

and the method

def onMarkupEndInteraction(self, caller, event):  
markupsNode = caller  
sliceView = markupsNode.GetAttribute(“Markups.MovingInSliceView”)  
movingMarkupIndex = markupsNode.GetDisplayNode().GetActiveControlPoint()  
logging.info(“End interaction: point ID = {0}, slice view = {1}”.format(movingMarkupIndex, sliceView))

regards,  
saima

---

<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:** [June 7, 2023, 9:45am UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/6 "2023-06-07T09:45:20Z")

</div>

You didn’t say anything about what the problem was, but from the code you pasted (which is identical to what we can see in the script repository) the problem I see is that you added an argument `self` to the `onMarkupEndInteraction` function, which won’t work outside of a class. Of course I can make assumptions all day but it would be easier if you told us what is the problem. Thanks.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [June 13, 2023, 1:35am UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/7 "2023-06-13T01:35:18Z")

</div>

> [@Saima](#):
>
> aving trouble with connecting mouse c

Hi Pinter,  
I have the markup control points already defined for the model nodes. I want a program where user can click on the markup point and can get the node number along with the x,y,z coordinates.

regards,  
Saima

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [June 13, 2023, 5:53am UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/8 "2023-06-13T05:53:02Z")

</div>

Hi,  
I got the control point I am clicking but why it is printing it multiple times. here are the lines of code.

In the main def process:  
markupsNode = slicer.util.getNode(inputFiducial.GetID())  
markupsNode.AddObserver(slicer.vtkMRMLMarkupsNode.PointEndInteractionEvent, self.onMarkupEndInteraction)

in the method within the class, def  
def onMarkupEndInteraction(self, caller, event):  
#print(“inside”)  
markupsNode = caller  
sliceView = markupsNode.GetAttribute(“Markups.MovingInSliceView”)  
movingMarkupIndex = markupsNode.GetDisplayNode().GetActiveControlPoint()  
print(movingMarkupIndex)

## the output is like below in the console.

Reloading module: SurfaceModelNodesSelector

* * *

inside

inside

inside

inside

inside

inside

2667

[-83.58309173583984, -56.84154510498047, 108.15825653076172]

2667

2667

2667

2667

2667

2667

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [June 15, 2023, 2:09am UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/9 "2023-06-15T02:09:30Z")

</div>

Hi,  
I am getting the index and the control point position with the following lines.

def onMarkupEndInteraction(self, caller, event):  
markupsNode = caller  
markupsNodeindex = int(caller.GetAttribute(‘Markups.MovingMarkupIndex’))  
pos = [0,0,0]  
markupsNode.GetNthControlPointPosition(markupsNodeindex, pos)

I am having problem with the slicer everytime I reload the application is not reloading properly to show the changes in the code i have to restart the slicer every time i do changes in the code so that it reflects inside the slicer application.  
Any thing how i can fix this?

regards,  
saima

---

<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:** [June 15, 2023, 2:04pm UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/10 "2023-06-15T14:04:33Z")

</div>

If I understand correctly you successfully solved the problem in this topic. Correct?

Your next question is unrelated, but as a quick advice, you can use the `Reload` button on the top of your module UI, or add some code to your `.slicerrc.py` so that Slicer sets up your scene correctly before continuing with testing/development. If you have more questions about this please do a search in the forum first then open a new topic if you don’t find an answer.

---

<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:** [June 25, 2023, 12:13pm UTC](https://discourse.slicer.org/t/select-vtkmrmlmodelnode-on-mouse-click/7348/11 "2023-06-25T12:13:36Z")

</div>

A post was split to a new topic: [Select locked control points in markuo](https://discourse.slicer.org/t/select-locked-control-points-in-markuo/30221)
