Extension Sources is a developer tool for SketchUp extension developers.
When developing a SketchUp extension you want to be able to load the extension from your source directory instead of directly in the SketchUp Plugins directory.
Background
In the past I’ve usually created a helper file in the Plugins directory to add and load my extensions I’ve been developing. Something like this:
# Helper file for loading extensions from external locations.
# Useful for extension development so the extensions can be loaded from the
# source repositories directly.
# Show the Ruby Console to catch any loading errors.
# SKETCHUP_CONSOLE.show
paths = [
'C:/Users/Thomas/SourceTree/extension-sources/src',
# 'C:/Users/Thomas/SourceTree/bezier-surface/src',
# 'C:/Users/Thomas/SourceTree/guide-tools/src',
'C:/Users/Thomas/SourceTree/tt-library-2',
'C:/Users/Thomas/SourceTree/TestUp2/src',
# 'C:/Users/Thomas/SourceTree/cleanup/src',
# 'C:/Users/Thomas/SourceTree/SelectionTools/src',
'C:/Users/Thomas/SourceTree/quadface-tools/src',
'C:/Users/Thomas/SourceTree/TrueBend/src',
# 'C:/Users/Thomas/SourceTree/rotate-and-scale/src',
# 'C:/Users/Thomas/SourceTree/image-opacity/src',
# 'C:/Users/Thomas/SourceTree/solid-inspector/src',
'C:/Users/Thomas/SourceTree/SpeedUp/src',
'C:/Users/Thomas/SourceTree/transformation-inspector/src',
'C:/Users/Thomas/SourceTree/sketchup-attribute-helper/src',
# 'C:/Users/Thomas/SourceTree/vertex-tools-v1',
]
ruby_files = []
paths.each { |path|
$LOAD_PATH << path
# Collect the Ruby files in the directory.
# Deferring the loading for later, first ensuring all paths are added to the
# load path..
ruby_files_filter = File.join(path, '*.rb')
ruby_files_basenames = Dir.glob(ruby_files_filter).map { |filename|
File.basename(filename, '.*')
}
ruby_files.concat(ruby_files_basenames)
}
ruby_files.each { |ruby_file|
# Load the Ruby files discovered.
# Using Sketchup.require simulates what SketchUp does upon startup and will
# not raise errors.
Sketchup.require ruby_file
}
This file would be copied and pasted between SketchUp versions and machines that I would use to test against. A simplistic approach, but unwieldy in the long run. The snippet above is a simplified version as the snipped grew as I needed additional handling for debugging Ruby C extensions – loading them directly from the compiled output etc etc. These mutations of the script that I needed per extension wasn’t always meshing that well and I kept copying the latest version around.
In the end I bit the bullet and decided to convert this snippet into an extension that I could install on each of my SketchUp installations I needed to work with. If improvements are made to the tool it propagates to all installed instances easily.
Extension Sources mark I
There’s more planned for this tool, but the initial version includes the most essentials:
Source management
UI to add/remove/edit paths for source directories that will be loaded. The tool adds these paths to the Ruby $LOAD_PATH
such that the extensions doesn’t need any adjustments to be loaded from their source directory. (As long as you don’t assume your extension is in the Plugins directory.)
The sources can be rearranged to control their load order. Though, beware that when installed on the user’s machines this it out of your control. But in development environment there might be cases where the load order is important. For instance if you have development tools that depends on some extension already being loaded.
Every source can be toggled on/off from the UI, allowing a source path to be ignored without having to remove it.
Transferring
The list of sources can be export and imported via a JSON file format. If your locations match between computers that’s an easy way to setup a new machine. Should the paths differ you can always just edit the JSON file manually before importing.
Filtering
If you have a lot of extension projects and find it hard to locate a particular item there’s also a quick-filter bar:
Development Tools
When developing it’s often needed to reload edited files. Extension Sources includes the ability to reload (calling load
) on all .rb
files under the source directory. (See the little “recycling” icon in the right hand set of actions per list item.) If you use this utility, beware that it will load all .rb
files it can find, not just those already loaded by your extension. (All though, I just had an idea…) If your extension have files that is conditionally loaded you’d want to add load guards.
Scanning for your extension projects
If you have all your projects under a root directory Extension Sources can scan this directory for your extension projects:
It will look for Ruby files with Sketchup.register_extension
accompanied by a support folder of matching name.
The scan might take a few seconds or minutes, depending on your file system and harddrive speed.
From the scan results the desired sources can be selected. The toggle will control whether the source path will be loaded or not.
Note that paths already added to Extension Sources will not appear in the scan results list.
Compatibility
- SketchUp 2017 and newer
- Windows, macOS