However I am trying to initiate a popup, and pass a UDT to its custom properties thru a gateway scheduled event. How do I pass this UDT into the popup using system.nav.openWindow()?
First, be aware that gateway events happen in the gateway, not the vision client. You will need to set up some message handling to have the gateway event script message all the active vision clients that might have that popup and then have those clients update the properties on the popup, if it is open.
Second, consider changing what data you are providing to the popup to begin with. Provide the path to the target UDT to the popup via a custom string property when opening, and use that path to indirectly bind the UDT members you plan to use to custom properties on the popup. If you then update that path property later to a different path(via your script), all the indirectly bound properties will update accordingly. This also means you only ever have to update the path, instead of tossing the entirety of the UDT data around your network/vision client.
Finally, for sending data to an existing popup window:
Using system.gui.getOpenedWindows(), you can iterate through a list of the open vision windows and upon finding the popup window, modify the value of the properties on the window at will, something along the lines of:
for window in system.gui.getOpenedWindows():
if window.path == "Designer/Path/To/Our/Popup" and window.rootContainer.someIdentifyingProperty == 'SomeIdentifier':
window.rootContainer.myCustomProperty = 'MY NEW VALUE'
You can also use system.gui.findWindow() to narrow down the number of windows you have to iterate through to find the popup window you want.
for window in system.gui.FindWindows("Designer/Path/To/Our/Popup"):
if window.rootContainer.someIdentifyingProperty == 'SomeIdentifier':
window.rootContainer.myCustomProperty = 'MY NEW VALUE'
That is a good clarification on the scope. I should've been more specific on this - I plan to use a client tag change event script to generate the popup, by monitoring the tag that is triggered via the scheduled gateway script (maybe this is overly complicated and there's a simpler way...but it's what I did).
That being said, I am mainly looking for a way to initiate a popup window while passing the UDT as a whole to the window, since the custom properties editor allows you to specify the data type as my custom UDT.
I may just pass each UDT component separately in the meanwhile. Even the event handler is only able to pass UDT instances if it exists as a window property, not as a tag. It seems that this just isn't an intended use case of UDTs and may be a limitation. I just thought everything would be cleaner if I could do it the way I specified.
It sounds like this is probably the only way forward - either this or passing each parameter of the UDT individually.
I just find it odd that you're able to define a custom property of data type UDT in a vision window, but you aren't able to pass a UDT instance to it through to the window through scripting when invoking an openWindow() method.
Custom properties of type UDT have numerous drawbacks. While UDTs are great for creating and maintaining complex tag hierarchies, their use with UI custom properties is an absolute cluster[expletive] and should die, die, die!.
Hi Phil, I tend to agree after looking into this (what I thought to be) simple issue. It sounded simpler to pass in 1 parameter than 3 (or more if I change the UDT definition in the future).
I will likely continue to store the tags/values within a UDT but pass things individually for the sake of simplicity.
The correct answer for structured data is to pass a string tagpath parameter. This lets you bind to target fragments as needed, without locking into any particular UDT type, and allows bidirectional bindings, too.