Hi all,
Currently we have a script in a toggle button event itemStateChanged
that iterates over 19 components, checking the current, previous high and previous low values, then sets a new previous high or low. So that's 57 values involved.
listOfZones = ['01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19']
if event.source.selected:
for item in listOfZones:
currentValue=event.source.parent.parent.getComponent('CZ '+item+' Current Value').value
if event.source.parent.parent.getComponent('CZ '+item+' Current Value').previousHigh == 1e-2:
event.source.parent.parent.getComponent('CZ '+item+' Current Value').previousLow = currentValue / 5
event.source.parent.parent.getComponent('CZ '+item+' Current Value').previousHigh = event.source.parent.parent.getComponent('CZ '+item+' Current Value').previousLow * 10
if currentValue < event.source.parent.parent.getComponent('CZ '+item+' Current Value').previousLow * 1.18 or currentValue > event.source.parent.parent.getComponent('CZ '+item+' Current Value').previousHigh*.9:
event.source.parent.parent.getComponent('CZ '+item+' Current Value').previousLow = currentValue / 5
event.source.parent.parent.getComponent('CZ '+item+' Current Value').previousHigh = event.source.previousLow * 10
I was reading some best practice tips on this thread (Do's and Don'ts when developing First Project with Ignition? - #2 by danielps1818) and am wondering if it would be reasonable to try and stuff this into a project script. It will only run on a radio button selection, so once or twice while the user is interacting with the screen.
While considering this, to try and move away from the getComponent()
stuff, I thought I would use custom props on the root container. That would mean, currently, 57 custom props and I would need a way to iterate over those based on the name as shown in the listOfZones
above. Something like event.source.parent._{zoneName}currentValue
equating to event.source.parent._01currentValue
or something similar. Then retreiving and or modifying those values.
Do you have any recommendations on this? Am I better off leaving it as is?
Thanks