Get Tagpath via scripting

I have a label component that when I click on it, it will write data to specific OPC tags.
What I want is to get the source's tag path via the event.source to use it in system.gui.tag.writeBlocking("tagPath", "valueToWrite")

val = system.gui.inputBox("Insert Value","Numeric only")
path = event.source.GetTagPath // But I am not sure how can I get the tagpath dynamically.

system.gui.tag.writeBlocking(path, val)

Hoping for your help.

Regards

How does the label know the tagpath? Did you bind to a tag? If so, is there any reason you don't want to use a bidirectional binding? (That would be the supported technique--simply write to the component property with the bidirectional binding, which will send it to the tag for you.)

Hi @pturmel

Thanks for the swift response.
And yes, the tag is already binded to the label component bidirectionally.

What I want is when I click the label component, it opens up an inputbox where the user will input value to write in a tag.

I can actually write on it specifying the tagpath in the script, however I am thinking if there is a way to automate it radther than coding it manually.

Regards,

system.gui.tag.writeBlocking(path, val)

This is not a system function, the correct one would be system.tag.writeBlocking().
Though technically supported with a single string and value, the function actually calls for lists, which you are not supplying.

the source of the event is a component, and has no idea of the tag path in the traditional since.

As @pturmel says, use a bi-directional binding. Not only is it the supported method, but it will be faster as well.

Use a popup with a text field component that is bi-directionally bound to the tag. Remove the bi-directional binding on the label.

1 Like

Thanks for the Tip!
And yes, I stand corrected about the script, it should be system.tag.writeBlocking

One more question, is it possie to pass the tag binding or tagpath as parameter in the pop-up menu?

Thanks and Regards,

Yes you can pass the tag path to the popup as a parameter. Then you can (and arguably should) use an indirect tag binding on the text box.