Let user place markups node

I am trying to make a simple script.

I have created a button which the user can press. When the button is pressed, the user should then be prompted to place one markups node, when this node is placed the user should then be prompted to place another node and then no more (so two markups nodes should be placed). And then i want to get the coordinates for these nodes.

I have tried to do this by using the function

placeModePersistence = 1
slicer.modules.markups.logic().StartPlaceMode(placeModePersistence)

and a while loop that should let the user to place two nodes. However the issue is that the code creates the markups node before the user has a chance to place it on the image. What is the right way to do this?

(I also tried using the interaction nodes but got the same problem)

Thank you

I’m not sure if it is a good idea to have a while loop like this; my feeling is that this will have problems with the Slicer application’s event loop.

Assuming you want this integrated in a scripted module. Instead of asking the user directly, I would set a “Remaining points: <# number of points>” label in the user interface. If the user should not proceed without adding all the fiducials, you can disable the rest of the user interface of the module until the count is fulfilled.

If you don’t want this integrated in a module, you could have a look at the templated markups (Markups — 3D Slicer documentation), which can help you placing markups in a workflow.