Scripting for text box's

So I’m relative new to Python and Ignition to say the least. I have a dropdown menu that has two column and several rows of data manually entered into it. I’m having difficulty with some of the callouts in the code. What I would like to do is take data from the table of the dropdown menu and post it into another TextFeild box. I have accomplished this just by using binding but I would like to know how to do it with code. Here is a picture of what I’m trying to do. When I select data something in the blue I would like the correspond number to appearing in the empty red text box.

Here is a rough outline of my terrible code. As a side note I don’t know why there is a error in my “if” statement.
def fillwell1x():
data = event.source.getComponent(“Table”).data
for row in range (data.rowCount):
for col in range (data.rowCount):
value = data.getValueAt(row,col)
#Error in if/else statment
if value = ‘’’<1 cfu/ 100ml (ECC)’’’:
print “Negative Test Results”
print “Positive Test Results”

Like I said I’m a big rookie at this so I’m excited to learn.

Regarding the if statement: in Python, “=” assigns a value while “==” checks for equality. I believe you want:

if value == '''<1 cfu/ 100ml (ECC)''':
   print "Negative Test Results"
   print "Positive Test Results"

Tip: to make code easy to read on forum as above, place three grave/reverse quote marks (usually to left of “1” on keyboard) before and after code.

1 Like

Ah I see. Thank you!

To do this in a script, you’ll need your script to:

  1. Get table data (yours already does)
  2. Get value from dropdown
  3. Find row containing value from #2 in Label column of table data
  4. Write value from Value column of table data in row found in #3 to the text box value
1 Like

Yeah my main problem is I’m unfamiliar with the callout in ignition.

if I just had a variable:

Value = “Hello World”
What would be the the line of code or call out to print that code into a new text box since just stating “print” wont define a location in ignition for it to print to?

You will need to get a reference to the text box you want to change, and set the .text property. See this page for an overview of the process:

Depending on where you are putting the scripting, you will probably end up with something like:

event.source.parent.getComponent('Text Field').text = "Hello World"


event.source.parent.getComponent('Text Field').text = Value

Alright I feel like I’m definitely getting closer on getting the solution on this code. Here is what I have. I read that it is easier to deal with as a python data set so I converted it over.

When I run it in the designer it tells me there is an error on line 3. Message says “Row sequence subscript must be an integer”. I’m confused because from what I read a .selectedStringValue can be an alpha numeric value. Additionally I know this code is not grabbing the corresponding dropdown. I’m just try to grab the first data point before I go onto bigger things.

code = pyData[selRow][0]

selectedStringValue can potentially contain numeric values, but the property itself is a string, thus that property will always return a string.

Not certain what the dataset on your dropdown looks like right now, but if it contains values that are easily converted to numerical, you can use Python’s int() function to cast the value as an integer (alternatively, you could use the Selected Value property on the dropdown instead of the Selected String Value)

code = pyData[int(selRow)][0]

However, if you’re trying to check the string value the user selected in the dropdown, then you already have that in selRow, so…

if selRow == "<1 cfu/ 100ml (ECC)":
 code = "Negative Test Result"

This is because selRow must be a number (not string) to designate row number in pyData. You are assigning the string in Label column to it by using selectedStringValue. Use selectedValue instead. With the values shown at the top, you’ll need to subtract 1 from selectedValue to get the row number (row numbering starts at zero, not 1).

1 Like

That worked yay!!!
Thanks for the help guys I’m kinda throwing myself into the middle of all this so I appreciate the helpful replies.

1 Like