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
project.scripts.functionname(event)

Withing the project script I an access any components on the screen using
event.source.parent.getComponent(ā€˜compnameā€™).property
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.