Thursday, July 21, 2011

Turn Your Plugin Into An Extension



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.

  1. Copy plugins/drawboat.rb into a new subfolder and rename it, plugins/drawboat/drawboat_loader.rb
  2. Create a new, empty file called plugins/drawboat.rb
  3. 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.

8 comments:

Thomas Thomassen said...

This feature would be more attractive if the Extension UI was improved. As it is now the scroll list is very small so it's hard to get a good overview.

And if every plugin added itself to the Extension list it'd be even hard to use the list. It does not currently let you do bulk operations, nor search/filter the list.

It just feel a bit too cumbersome to use and too many clicks to be a feature one want to use often.

Scott Lininger said...

I agree, Thomas. We're spending a lot of time around here talking about plugins and extensions. I've added your thoughts to a brainstorming doc I have. Thanks!

Jim said...

+1. An improved Extensions dialog would make them a more attractive option.

This is one of my experiments for dealing with Extensions - pre-select Extensions prior to launching SketchUp.

Thomas Thomassen said...

Another nice addon to the Extension manager would be if plugins also registered their menus and toolbar buttons - so people could select what UI items to use.

Aerilius said...

... and eventually to make extensions accessible for other plugins without dirty hacks (which icons and commands does an extension provide?). So plugin authors could offer innovative ways to customize the UI, like Jim's custom toolbars, or this experiment.

SketchupExtension could definitely have great potential, and it could save us from re-inventing the wheel ;-)

Dan Rathbun said...
This comment has been removed by the author.
Dan Rathbun said...

SketchupExtension class needs a @path getter method.

Dan Rathbun said...

[code sample]
SketchupExtension and rbs rubies