Loading plugins only when needed
-
After writing the Mortise & Tenon plugin I realized it could be the basis for other woodworking furniture joints ie. Dowels, Dovetails, Biscuits, etc. When starting to develop these additions it became useful to think of each program individually as this should make the logic and program easier to develop and follow. Then I thought that adding detail to joints in a sketchup furniture design is a very small part of what needs to be done and I didn't want these plugins taking up resources when not needed. So I devised a method of using a loading script that only populates the menu but waits for the first use to load the plugin. It seems to work well but I thought I would post the example to see if there are hidden problems I have not encountered or thought out. The included files are:"loadK2WS_Tools.rb" placed in the plugins directory to automatically load other files, "KK_MortiseTool_X.rb" this is the actual tool script, and "Test_MortiseTool2.rb" the file that creates the menu items and loads the tool plugin as needed (these files need to be placed in a K2WS_Tools directory in the plugins directory ). Note: as written only the Tenon and Mortise tools are available the M&T_Joint and LT_Joints do not function until the tool script is loaded the first time by the Tenon or Mortise tools. This was done to demonstrate that the main tool script file did not load until requested.
Thanks for looking (comments +/- appreciated)
Keith
-
So "loading plugins only when needed" - is not for all plugins? Just for Mortise & Tenon?
-
Well it would be very good plugin if it was for all.
-
Seems like a good idea. But wouldn't you instead have a long list of available plugins, instead of a long list of loaded plugins?
-
The concept is usable on any plugin however the file loading and menu would need to be separated into a separate plugin. Yes it would be nice to have a list and load from a list but so far that has seemed to evaded the plugin writers. The way I made this the menu for the tool will exist which I think is handy for the user but only load as needed. I mainly put this out for comments and possibly starting some thinking on a different approach to the management problem. Also I wanted to know if there were any problems obvious to others that I overlooked as I am rather a newbe to SkethcUp & Ruby programing.
Keith
-
Keith,
I think this is the way to do, because it speeds up the start of the Sketchup application.
I introduced this approach for my own plugins with LibFredo6 3.6. I called it "two-phase loading" (only the files bootstrap_... are loaded at SU startup time). Actually, you may see a small message in the status bar indicating the file loading the first time you use the plugin. Also the time for the second phase is indicated in the About... box.
I use a slightly different method but it does not matter.
This save a few hundreds milliseconds for each plugin, so seconds at the end
Fredo
Advertisement