I’m programming my first plugin and I’ve come across a situation in which I want to find out if an HTML dialogue is open or not. If it is I want to close it with dialog.close which seems trivial enough but I cant find any way to get the reference to the object.
Within my method I can manipulate it easy enough but once I exit the method and return to an idle state while I wait for my user to interact with a HTML link or something else I’m stuck trying to figure out how to get back.
I guess a simple way to ask is, is there a global reference to the dialogue I can use to get back once the script has completed?
Do not use global references. There is never any good reason for your code to be outside of your own namespace module or any of it’s plugin submodules.
Within your plugin submodule you use locally persistent references. They can be a local module constant, a @@ module variable, or a @ instance variable (since a module is an instance of class Module.)
The SketchUp application is a user driven environment that is better suited to event driven programming.
You need to stop thinking of and organizing your code in a linear manner. (ie, running a linear script as a command / macro.)
Instead you load your code and when the user activates a command (menu or toolbar button) to open the dialog, the method that creates it will assign the reference to a persistent variable within your submodule.
Where @options is a hash within your plugin submodule …
@dialog = UI::HtmlDialog.new(@options)
!@dialog.nil? && @dialog.visible?
I am new to Ruby so I was unaware of the @ instance variables.
This is exactly what I was looking for, thank you! I was trying to find a way to access the varialbe that i assigned the dialog to outside of the block I was in and this is exactly it. Thanks for your help!