Perspective UI not updating in browser when modifying Drawing elements via message handler

I I am a beginner of the ignition system. I wrote a simple demo where clicking the button changes the color of the graphic, and then the color is written to the tag.This way, it can work properly. Then I attempted to run the same script in the root's message handler program. The message was successfully received, the tag wrote the correct value, but the graphic color did not change.

button click script:

def runAction(self, event):
    element = self.getSibling("Drawing1").props.elements[0]
    oldColor = element.fill.paint  
    system.tag.writeBlocking(["[default]DrawingTag/OldFill"], [oldColor])
    if oldColor == "yellow":
        newColor = "green"
    else:
        newColor = "yellow"
    element.fill.paint = newColor
    system.tag.writeBlocking(["[default]DrawingTag/NewFill"], [newColor])

message handler scripts:

def onMessageReceived(self, payload):
    element = self.getChild("Drawing1").props.elements[0]
    oldColor = element.fill.paint 
    system.tag.writeBlocking(["[default]DrawingTag/OldFill"], [oldColor])
    if oldColor == "yellow":
        newColor = "green"
    else:
        newColor = "yellow"
    element.fill.paint = newColor
    system.tag.writeBlocking(["[default]DrawingTag/NewFill"], [newColor])

Add: when the message was received, the color of the graphics in the designer changed, but the web interface remained unchanged.

element = self.getChild("Drawing1").props.elements[0]
oldColor = element.fill.paint 

element.fill.paint = newColor

I'd try switching that to this.

drawing = self.getChild("Drawing1")
oldColor = drawing.props.elements[0].fill.paint

drawing.props.elements[0].fill.paint = newColor
1 Like