I'm working on a template for liftstations. I have a pretty robust UDT that holds all the data for the liftstation. My current issue is trying to get the indicator for the lead, lag, and laglag starting levels to position on the screen at load. I found a really neat discussion on moving a component dynamically here:
The 10.0 is just a placeholder for right now. What I would like is to position these groups relative to their values in the PLC (i.e., 3.0, 3.5, 4.0.) The wetwell (10') graphic is 560 pixels high, so I want to position the Lead indicator 3*56 pixels from the bottom, etc. The user can then click and drag the indicator to change the level.
The problem I am facing is there is no x position for the group (Pump1Lead) in the vision property editor to bind to. Also I'm still in the print("Hello World") level of Python coding. I figure this has to be a script somewhere, but I not sure if it is at the template level or the point of instantiation. It seems the likely option is the propertyChange event at the template level, but I'm not sure what property changes on load or takes focus. On the window where the template is instantiated I looked at the internalFrameActivated event, but when I tried to drill down into the property I can't find the group in the template, only the raw data in the UDT.
Any help would be greatly appreciated. Thanks folks!
Moving a group of components is done with scripting using system.gui.transform. For this use case, the transform could probably be triggered using the value property of the numeric label in the propertyChange event handler.
The script would look something like this untested example:
# Made for the propertyChange event handler of a grouped numeric label
if event.propertyName == 'value':
# Get the parent template for height calculation
liftStation = event.source.parent.parent
# Use the height of the template as the maximum scaled height
maxHeight = liftStation.height
# Get the component to be moved
pumpGroup = event.source.parent
# Define the maximum expected value
maxValue = 100
# Convert the current value to a percentage of the max value
percentMax = event.newValue / maxValue
# Use the percentage to scale the value to the height,
# ...but since the bottom of the template is zero,
# ...and y coordinates start at zero from the top,
# ...the value must be inverted to correctly position the group
groupY = maxHeight - (percentMax * maxHeight)
# Move the component group to the new position
system.gui.transform(pumpGroup, newY = groupY)
There could be a caveat to performing a transform on components within a template if the size of the template was stretched or squished in some way while positioning it in the window editor. If you run into any wierdness of this nature, this post could provide a way to fix it: How to transform a component inside of a Vision template