Access Windows component from a Project Script on Window Open

I would like to access some components in a screen when the screen opens, but from a Project Script so
it can be used by multiple screens. The screens will have some similar components (i.e. droplist.selectedValue)

I currently call the project script on a button press, now I want to call the same script on screen open.
I pass the EVENT to the project script

Withing the project script I an access any components on the screen using
since I passed the “event”.

Now I need to call the same script on screen open and I get the error it can’t coerce the “event” parameter into a integer…
I do not know what to pass from the open event…

This should work. I use it in many places. Please post your code so we can work out what’s going on.

Can you be more specific when you say “screen open” event? (there are a few)

The event object content varies by event type. The biggest difference in your case is that events on the Vision window deliver the window itself as event.source, while all of the component and container events have that component as event.source. Getting to the root container differs based on source. For a window it is root = event.source.rootContainer. For a root container event (propertyChange, perhaps), it is just root = event.source. For components, you need one or more .parent references.

Consider resolving the root container in the calling event, passing it as an additional argument to your project function.

This is where I will (mostly) always use the system.gui.getParentWindow(event).rootContainer function to get the rootContainer regardless of the object. Then you can use the same code everywhere and not worry about if it’ll work or not

1 Like

Thanks guys!! Got it working with your suggestions. I’m fairly new to Ignition scripting and wasn’t familiar to the hierarchy scripting. I changed to passing the root container to the VisionWindowOpened event and then drilling down to the component.