This is how I do it, it is absolutely not the best way, and not even the right way, but it works for my workflow. I have a 5-button programmable mouse, so I’ve set a hotkey/shortcut of ;
to add a markup point and then programmed a mouse button to type that key. You can also just type ;
from the keyboard. Anyway, this shortcut runs a python function that sets the interaction node to placement node, then locks all markups for that node. For whatever reason, it locks all nodes except the one that’s just been placed, but since I place a lot of points in a row, it’s good enough for me.
Locked markups are saved as locked and reloaded as locked. You can look at the JSON file that has the markups and check the “locked” attribute and see that it is set to “on”.
The right way, as described above, is to change the default markup node to be locked. I’ve been unable to get this to work but I haven’t spent enough time debugging it since my very hacky method works for me.
The shortcut function is:
def hh_place_fiducial():
try:
interactionNode = slicer.app.applicationLogic().GetInteractionNode()
interactionNode.SetCurrentInteractionMode(interactionNode.Place)
mod = slicer.util.getModule("Markups")
ml = mod.logic()
n = slicer.util.getNode(ml.GetActiveListID())
ml.SetAllMarkupsLocked(n, True)
except AttributeError:
pass
And to set it as a hotkey/shortcut: (You don’t need the loop below for setting only one, I have a number of shortcuts I’ve defined but edited those out for clarity.)
shortcuts = [
(';', lambda: hh_place_fiducial())
]
for (shortcutKey, callback) in shortcuts:
shortcut = qt.QShortcut(slicer.util.mainWindow())
shortcut.setKey(qt.QKeySequence(shortcutKey))
shortcut.connect( 'activated()', callback)
(As an aside, this what I have tried for setting the default node to be locked, but it does not work. If anybody’s got ideas on why, any help would be awesome.)
### THIS DOES NOT WORK
defaultMarkupNode = slicer.vtkMRMLMarkupsFiducialNode()
defaultMarkupNode.SetLocked(1)
slicer.mrmlScene.AddDefaultNode(defaultMarkupNode)