It looks like the default lock status for markup nodes is unlocked by default - looking in the vtkMRMLMarkupsNode() constructor, it sets Locked to 0 on the second line of code.
I almost never move markups, unless to move them back after creating them and accidentally moving them if they’re unlocked. I basically have added hitting the “lock all” button periodically to my workflow to make sure I don’t inadvertently move them around.
Is there a reason they’re unlocked by default? Would there be any interest in an option for toggling unlocked/locked on creation?
As far as I can see, moving markup points is very common: most often you place it approximately in one view, potentially in 3D, then you verify and fine-tune the position in multiple, zoomed-in slice views. If that’s not your workflow then no problem, you can modify default properties of new nodes by specifying a default node - see examples in script repository. You can put those few lines into your
.slicerrc.py file to make it always the default on your computer.
Ah, ok - that’s MUCH cleaner than my solution. Right now I have a hotkey set to place a fiducial, and in that function I run SetAllMarkupsLocked().
Thanks Andras! Hope you’re doing well.
This is a very stale thread, sorry, but I’m finally getting to doing this the right way rather than my old hacky solution.
I’m trying to make a default markups node like this:
defaultMarkupNode = slicer.vtkMRMLMarkupsNode()
but when I do this, new markups still show up as unlocked. What am I doing wrong here?
It is all good, you just need to create more concreate default node class(es). To prevent moving line node endpoints after placement:
defaultMarkupNode = slicer.vtkMRMLMarkupsLineNode()
Hmph… something still missing, I put both these code snippets in my
.slicerrc.py file and when I make a new markup node and add points, they’re still unlocked. Is there something I need to do to tell the
vtkMRMLMarkupsFiducialNode that it needs to use those particular
vtkMRMLMarkupsNodes as defaults? (This question likely doesn’t make any sense…)
For a Fiducial node, the following works for me where the control points are not movable and are locked. If it doesn’t work for you, download a new Slicer version, don’t install any extensions, and test this snippet.
defaultMarkupNode = slicer.vtkMRMLMarkupsFiducialNode() # fiducial node markup
OK, that does make the point immovable, but it does not show as locked in the control points list. I’m also not able to rename the point by right-clicking on the point - it’s completely locked and not modifiable.
What I’m looking for is to lock the position by default but be able to rename it via right clicking.
My hacky work-around has been okay thus far, so if this takes any real amount of time to look into, no need to bother.
Yes the example code has been setting the Locked state for the node which applies to all control points rather than setting the locked state for the individual control point. The locked state in the example code is indicated by the locked icon in the GUI as shown with the tooltip.
Ah, okay. Is it possible to make a default control point that is locked?
Control points are currently always initialized unlocked. You could lock them without Slicer core change by adding an observer to control point add event and lock every newly added control points. However, if “locked by default” is a common need then it would be quite easy to add a flag for this in the markups node.
I guess you need locking because you want to avoid accidental modification of placed points (e.g., when you rotate the view you may accidently click on a control point), which must be a common need. @smrolfe How do your users solve the problem of accidentally misplaced control points?
@hherhold would you mind describing your use case on this page so that we can get more complete picture of how people use markups?
Yeah, as described in the use case I added (below), I set up a shortcut key to run a quick function that locks all control points. The minus is that it locks all the ones done thus far, so the one just placed is unlocked, but it’s been better than nothing. (Yes, very hacky.)
I’ll take a look at adding an observer - that’s far more elegant.
Yes, this is a common need. We’ve had some requests for an undo button to correct these kind of mistakes. Using a landmark template should help with this. If the landmark points are locked when the template is created, they can be placed but not moved in the scene (by default) when the template is imported.