But when I call the addNode method in the script it’s getting into an infinite loop(because of the functions calling each other probably). Even after I commented addNode method its looping for every mouse moment.
You only need to create single markups fiducial node. You can add any number of control points to it. To keep placement mode active, enable “persistent” option.
I would recommend to put a qSlicerMarkupsPlaceWidget widget on your module GUI to activate/deactivate point placement. It ensures that the correct markups fiducial node is selected, enables/disables placement and persistent option. You can specify persistence by adjusting placeMultipleMarkups property.