And you can edit comments to fix formatting instead of reposting the same thing… ):
ah, sorry everyone.
I think you need to change the bottom part (starting line 64) to:
data = [{"value": unit, "style": {"classes": color}}
,{"value": company, "style": {"classes": color}}
,{"value": location, "style": {"classes": color}}
,{"value": volts, "style": {"classes": color}}]
ds.append(data)
Previously you were setting the style key to a value, whereas the value of the style key should be a dictionary/object with keys within it.
You also have a large number of singular tag reads in the script which will significantly impact performance, especially if you have a reasonable number of units. You should consider changing this to read tags all at once and then process the values. As a point of reference, I changed a colleague’s script from reading 5 tags at once, many times over in a loop, to reading all tags at once and it reduced the script runtime to something like 2% of the time.
You’re a genius, it worked, and it took only seconds, on vision it would take like 2 minutes. Thanks all for the help, especially you.jake
It could be much faster than seconds, you could get this down to ms ![]()
Trust me, with vision being so slow this is ridiculously fast. I actually had code to change the button so people knew they had hit it and it would change back after words.
One last thing, I have the columns setup in the table, but they are showing up as column_1 - column_4. Do I need to do something special?Thx, jake
Try this (completely untested, and I haven’t replaced the reads in the getColor function either):
def Load(caller):
units_tag = caller.session.props.auth.user.userName
hide_customer = False;
if units_tag == 'TOPSDemo':
hide_customer = True
units = system.tag.readBlocking(['[default]' + units_tag + '/Units'])[0].value.split(',')
unitList = caller.getSibling("Units")
#ds = system.dataset.clearDataset(unitList.props.data)
ds = []
units_enabled = [tag.value for tag in system.tag.readBlocking(['[default]' + unit + '.enabled' for unit in units]))
units_comploc = [tag.value for tag in system.tag.readBlocking(['[default]Disabled-' + unit for unit in units]))
units_company = [tag.value for tag in system.tag.readBlocking(['[default]' + unit + '/Company' for unit in units]))
units_location = [tag.value for tag in system.tag.readBlocking(['[default]' + unit + '/Location' for unit in units]))
units_compv = [tag.value for tag in system.tag.readBlocking(['[default]' + unit + '/CompMainsVoltage' for unit in units]))
for idx, unit in enumerate(units):
#system.gui.messageBox(unit)
color = GetColor(unit)
company = ""
location = ""
volts = ""
d = units_enabled[idx] #system.tag.readBlocking(['[default]' + unit + '.enabled'])[0].value
if d == False:
comploc = units_comploc[idx] #system.tag.readBlocking(['[default]Disabled-' + unit])[0].value.split(',')
company = comploc[0]
location = comploc[1]
volts = "NA"
else:
if hide_customer == True:
company = 'NA'
location = 'NA'
else:
company = units_company[idx] #system.tag.readBlocking(['[default]' + unit + '/Company'])[0].value
location = units_location[idx] #system.tag.readBlocking(['[default]' + unit + '/Location'])[0].value
compv = units_compv[idx] #system.tag.readBlocking(['[default]' + unit + '/CompMainsVoltage'])[0]
if compv and compv.quality.isGood() == True:
volts = "%4.1f" % compv.value
else:
volts = "NA"
data = [{"value": unit, "style": {"classes": color}}
,{"value": company, "style": {"classes": color}}
,{"value": location, "style": {"classes": color}}
,{"value": volts, "style": {"classes": color}}]
ds.append(data)
unitList.props.data = ds
You could go further and combine this into a single read, but this will give a huge improvement as it is
cool, I try that out when optimizations come into play.Thx, any thoughts on the headers not showing up from the controls props?
Whoops, replace this with:
data = {"Unit": {"value": unit, "style": {"classes": color}}}
,{"Company": {"value": company, "style": {"classes": color}}}
,{"Location": {"value": location, "style": {"classes": color}}}
,{"Volts": {"value": volts, "style": {"classes": color}}}
ds.append(data)
I edited the other post, removed the outer list brackets []
It doesn’t like it then, the commas confuse it seems like
Silly, I should have replaced the square brackets with curly. Try again, edited post.
That made the list not do anything again. I tried this and it still didn’t work:
unitList.props.data = ds
unitList.props.columns[0].field = "Unit"
unitList.props.columns[0].field = "Company"
unitList.props.columns[0].field = "Location"
unitList.props.columns[0].field = "CompVolts"
It’s really strange.
Got it, thx for the help, this worked, not sure why not before:
data = {"Unit": {"style": {"classes": color}, "value": unit}
,"Company": {"style": {"classes": color}, "value": company}
,"Location": {"style": {"classes": color}, "value": location}
,"CompVolts": {"style": {"classes": color}, "value": volts}}
