When (and why) might "file_loaded?" be needed?
-
In some plugins I've perused, there is code like this:
unless file_loaded?('MyPlugin.rb') UI.menu('Plugins').add_item('My Plugin') file_loaded('MyPlugin.rb') end
I'm curious about when and why SketchUp might try to reload a plugin. Does anyone know the answer to this?
-
It's more of a convenience for the developer - when you reload your script you don't get lots of duplicate menu entries.
-
It's there to stop more than one instance of the plugin loading into the menu/context-menu etc.
If you hadn't added this trap then this might happen if you typed
load "MyPlugin.rb"
after you have already got it loaded - e.g. automatically at startup.It's not going to have to stop these potential duplicate menu items unless you try to 'load' the script more than once - e.g. while you are testing it, or perhaps when you have a script in a sub-folder that doesn't auto-load, but it might be loaded by another script [that is itself already loaded] under certain circumstances, and potentially these circumstances might occur more than once in that session - but you only want the one menu/context/toolbar item...
Advertisement