Mouse click tag write

How do you do a mouse click on a button and write a value to a tag from a numeric entry on the same window.

Open the Button Component Scripting and go to the “Set Tag Value” tab.
Then, click the tag icon on the right side of the input box to choose the destination tag. Then click the chain icon to bind set the value to the numeric entry value.

This is one of the more basic functions of Ignition - I suggest you take a look at Inductive University to see how to do these sort of things.

1 Like

yes, I have used what you suggested before. the problem is the I have to select between 3 equipment choices and write to 3 different tags based on the equipment choice

1 equipment choice to 1 tag write.

If I understand correctly that you have one entry field, one tag write button, and and equipment selector elsewhere that determines which tag will get written the value from entry field when tag write button is pressed, you’ll need to edit the script on the Script Editor tab to read the equipment choice and then write the value to tag based on equipment choice. Something like:

equipmentChoice = event.source.parent.getComponent("equipmentChoiceComponent").text
value = event.source.parent.getComponent("valueEntry").text
if equipmentChoice == 1:
   tagName = "equipment1TagName"
elif equipmentChoice == 2:
   tagName = "equipment2TagName"
elif equipmentChoice == 3:
   tagName = "equipment3TagName"
system.tag.write(tagName, value)

An easy way to find the correct paths for those “even.source.parent…” lines is to use the binding button set tag value tab and then flip over to the script tab to see what it put in there.

You can search “Python case” (doesn’t exist, but will lead to results regarding if/elif/else construct), etc. to get more details on various Python scripting methods.

1 Like

This is what I have but it says tagname is not defined

equipmentChoice = event.source.parent.parent.getComponent(‘Form Dropdown List’).getComponent(‘Dropdown’).selectedValue
value = event.source.parent.parent.getComponent(‘Form Numeric Text Field 1’).getComponent(‘Numeric Text Field’).intValue
if equipmentChoice == 0:
tagName = “FURNACE_BAGHOUSE/LimeDryerBHUsage”
elif equipmentChoice == 1:
tagName = “FURNACE_BAGHOUSE/LimeFurnaceBHUsage”
elif equipmentChoice == 2:
tagName = “LIME_SILO_2/LimeRotaryBHUsage”
system.tag.write(tagName, value)

I’m going to guess that error refers to line 9 and the reason is none of the ifs were true. If you add this code before the ifs you’ll get a message telling you what the equipmentChoice is:


EDIT: the following does not apply; selectedValue is an integer
That said, selectedValue is probably a string, in which case you want to put quotes around your values in the if statements like:

if equipmentChoice == "0":

By the way, you can make code show neater in the forum if you put three grave marks (`) before and after it in your posts.

it gave me a -1 in the gui box

-1 is the selectedValue when nothing is selected

The drop down is listed below Value is the numbers and Label is the string
“0”,“Dryer Baghouse”
“1”,“Furnace Baghouse”
“2”,“Rotary Baghouse”

Your dropdown has a selectedValue property shown as Selected Value in the Property Editor. The value there will be -1 until you select something. When you select something, it should change to the corresponding value in your list. You can easily test this in the Designer in preview mode where you can display the Property Editor and see this value while you make selections. Or you could temporarily bind a label to selectedValue.

You’ll probably want to put a check in your code that prompts the user to select the equipment before trying to write that tag. Something like:

if equipmentChoice == -1:
   system.gui.messageBox("You must choose the equipment before writing a value", "Choose equipment")

Or disable the button if selectedValue == -1.

I think I figured the issue out when I click submit I am putting the data in a database, it clears the values out so I automatically get the qui message and it puts the -1 in for the no selection value.

and tagName is still not defined

Yes, you’ll want to grab the values you need before clearing them. tagName is only defined in your if statements for equipmentChoices other than -1 so if equipmentChoice is -1 tagName does not get defined. You’ll want to skip the tag write if equipmentChoice is -1 to avoid the tagName undefined error.

ok, How do I go about doing that.

if I use mouseEntered instead of mouseClicked it doesn’t show the gui message but it still show tagName undefined error

Something like this should work, assuming you’re getting these values before clearing them:

equipmentChoice = event.source.parent.parent.getComponent('Form Dropdown List').getComponent('Dropdown').selectedValue
value = event.source.parent.parent.getComponent('Form Numeric Text Field 1').getComponent('Numeric Text Field').intValue
if equipmentChoice == 0:
   tagName = "FURNACE_BAGHOUSE/LimeDryerBHUsage"
elif equipmentChoice == 1:
   tagName = "FURNACE_BAGHOUSE/LimeFurnaceBHUsage"
elif equipmentChoice == 2:
   tagName = "LIME_SILO_2/LimeRotaryBHUsage"
   system.gui.messageBox("You must choose the equipment before writing a value", "Choose equipment")
   return # exit script before tag write if no selection
system.tag.write(tagName, value)

it says return is outside function

had to add ‘return’ around it. but it still does write the value