Force a given event?

I was wondering if there is any way to force a given event script to run via Jython, even if the event the script is bound to does not occur.

For example, I have an event script that executes on visionWindowOpened for one of my popup windows. I just decided I would like to add a button to run the script again. Instead of copying and pasting the code to the button, I was wondering if there is any way to force or simulate the event so the script runs.

To be more specific, I cannot copy and paste the code to different objects since all the references to other objects will no longer be valid (I would need to make modifications to traverse the event object via the .parent property to access the other objects properly).

Thank you

Maybe are some workarounds, like put the code in some property change event for a custom property and change the value of that custom property or calling some java method, like firePropertyChange, but I think that the “official” way is to use Script Modules.

For the particulary case that you mention, you can move your script to some module in Script Module (for example, app.somepackage.somemodule) and create a function (for example, doSomething) with a parameter called event.

Then, your first line in that function would be something like this:

root = system.gui.getParentWindow(event).getRootContainer()

In that function, you must access a component in this way (similary that you used to do it, but replacing event.source for the root object:

comp = root.getComponent("componentName")

In that way, you can call this function from visionWindowOpened or actionPerformed in a button, with the same signature:

app.somepackage.somemodule.doSomething(event)

If you need more arguments, besides event, just add the ones you need.

I hope that make me understand.

Regards