-
Notifications
You must be signed in to change notification settings - Fork 145
Development Setup
Here's a suggested development setup.
Working directly in the SketchUp Plugins directory makes version control of your source code a challenge. It's much easier to keep the source separate and make SketchUp load your extension from this custom location.
Lets say you have a project with a file structure like this:
~/Source/ExampleExtension/.git/
~/Source/ExampleExtension/.gitignore
~/Source/ExampleExtension/src/hello.rb
~/Source/ExampleExtension/src/hello/main.rb
~/Source/ExampleExtension/tests/
To load your extension from this directory you can create a file in your Plugins folder that add additional directories to $LOAD_PATH
.
Note that this should only be done in your development environment and not on your users' machine.
Create a file in your Plugins folder: <...>/Plugins/!external.rb
Within the file you can specify what additional directories to load:
SOURCE = File.join(ENV["HOME"], "Source").freeze
paths = [
"#{SOURCE}/ExampleExtension/src",
# Add more as needed here...
]
# Un-comment if you want to see any potential loading errors in the Ruby
# Console:
# SKETCHUP_CONSOLE.show
paths.each { |path|
$LOAD_PATH << path
Dir.glob("#{path}/*.{rb,rbs,rbe}") { |file|
Sketchup.require(file)
}
}
If you don't make changes to menus, toolbar or class inheritance you can in most cases reload extensions without having to restart SketchUp between every change.
One way to make it easier to reload the whole extension is adding a small utility method that you can call from the Ruby Console:
# ~/Source/ExampleExtension/src/hello/debug.rb
module Example::HelloWorld
# Reload extension by running this method from the Ruby Console:
# Example::HelloWorld.reload
def self.reload
original_verbose = $VERBOSE
$VERBOSE = nil
pattern = File.join(__dir__, '**/*.rb')
Dir.glob(pattern).each { |file|
# Cannot use `Sketchup.load` because its an alias for `Sketchup.require`.
load file
}.size
ensure
$VERBOSE = original_verbose
end
end # module