Force window to redraw

I have a popup windows which I open up to look at a particular type of sensor. On the popup are several different numeric entry fields, and a “setup” button. The “setup” button brings up a second popup, on which I check or un-check boxes to determine which fields show up or not on the first popup, based on which characteristics this particular sensor has. So, basically, check a box on popup 2, another field appears on popup 1, using a visibility binding.

If I’m not using a particular item, as well as making it invisible, I also use system.gui.transform to adjust the position of the remaining fields and resize the window, so I don’t have ugly looking gaps everywhere. I run a script when the first popup opens to adjust the positions. This all works just fine, but the only thing is, if I make adjustments on my second popup, the visibility immediately changes, but to make the script re-run to adjust positions and sizes, I have to close both popups and then re-open the first.

Is there a way to
(a) force the first popup to close and re-open when the visibility of an object on it changes?
(b) have the second popup force the first popup to run its startup script again?
© achieve this in some other neat way without copying the entire script into a property change script for every object? (I don’t mind adding a short script to each object to call the main script, but if I ever want to change the main script I don’t want to have to change it in 15 places)

Put the main script in a custom method on the root container, calling it from wherever you need.