How to change the color of markup node from python script?

Operating system: Ubuntu
Slicer version: 4.10
Expected behavior: Color changed
Actual behavior: does not

Hi,

I am trying to change the color and the text scale of a markup node. the text scale works but the color does not. Here is the code:

     mNode = getNode('myMarkUpNode')
     mDisplayNode=slicer.vtkMRMLMarkupsDisplayNode()
     slicer.mrmlScene.AddNode(mDisplayNode)
     mNode.SetAndObserveDisplayNodeID(mDisplayNode.GetID())
     mDisplayNode.SetTextScale(1)
     mDisplayNode.SetColor(0,1,0)

How can I fix this?
Thanks!

No need to create a new display node, just use the current one. By default, markups are selected, so you may want to change color of the selected markups, too.

mDisplayNode = getNode('myMarkUpNode').GetDisplayNode()
mDisplayNode.SetTextScale(1)
mDisplayNode.SetColor(0,1,0)
mDisplayNode.SetSelectedColor(0,1,0)
1 Like

Thanks a lot for the quick reply and the valuable information. It seems SetColor does nothing. I only used SetSelectedColor and it works:

getNode('myMarkUpNode').GetDisplayNode()().SetSelectedColor(0,1,0)

SetColor changes color of non-selected markups. Uncheck the checkbox next to the markup’s name in Markups module and you’ll then see how non-selected color is used.