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') endI'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...
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement