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ā¦
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
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.