Turn Your Plugin Into An Extension
July 21st, 2011 | Published in Google SketchUp
Around the office here we're always amazed at the awesome Ruby scripts you developers create. They make SketchUp more productive, smarter, and downright snazzy. So it's no surprise when we hear from users who have a lot of plugins installed.
Plugin management can get really difficult, though. If two scripts conflict with each other somehow, SketchUp can go haywire, and figuring out which scripts are the culprits can require a lot of detective work. If only all of the ruby programmers out there used SketchupExtensions... ahh, the world would be so much nicer.
SketchupExtensions are a handy-dandy way for you to package your plugin that is easier for users to toggle on and off. You can see the extensions you already have under Window > Preferences > Extensions. With a quick click, you can learn about who authored each of them and can even turn 'em on and off. It's dandy!
And the cool thing is that an extension is nothing but a normal Ruby plugin wrapped in a little bit of extra code. Making one of your own is easy and well worth your time. Here are several advantages:
- Makes it easier for your users to turn off your script if they don't need it at the moment
- Makes customer support easier for you, because you can track plugin versions
- Gives you a handy promotional space to put contact info, website details, etc.
- Keeps everyone's scripts better isolated so there are fewer cross-script conflicts
Let's walk through an example. Say you have a script called drawboat.rb. It already works. Now you just want to make it an extension. Here are the steps.
- Copy plugins/drawboat.rb into a new subfolder and rename it, plugins/drawboat/drawboat_loader.rb
- Create a new, empty file called plugins/drawboat.rb
- Put the following code into plugins/drawboat.rb
# Load the normal support files.
require 'sketchup.rb'
require 'extensions.rb'
# Create the extension.
ext = SketchupExtension.new 'BoatCreator Beta',
'drawboat/drawboat_loader.rb'
# Attach some nice info.
ext.creator = 'DrawingBoats, Inc.'
ext.version = '1.0.0'
ext.copyright = '2011, DrawingBoats, Inc.'
ext.description = 'Draw boats! Visit drawboats.com for support.'
# Register and load the extension on startup.
Sketchup.register_extension ext, true
That's all there is to it. When you restart SketchUp your plugin will load as before, but now people can control it in the Preferences panel. We highly recommend that you do this with all of your plugins that extend SketchUp's UI with buttons or menu items.