Reloading my plugins

I’ve set up SketchUp to load extensions directly from my development folder so i don’t need to create any intermediate RBZ. The script I have in my plugins folder look like this:

pattern = "D:/Sketchup Plugins/Working Dir/*/src/"

Dir.glob(pattern).each do |dir|
  $LOAD_PATH << dir
  Dir.glob("#{dir}/*.rb").each { |p| require p }
end

This allows each project to have its own folder, corresponding to a Git repo. Each such folder has a src folder corresponding to what will become the RBZ, but also allows additional folders, e.g. for unit tests, 3D models icons are based on etc. I know ThomThom does something similarly, but explicitly lists projects to load rather than iterating all possible projects.

In my main extension file I have this method for simply reloading the extension.

# Reload extension.
#
# @param clear_console [Boolean] Whether console should be cleared.
# @param undo [Boolean] Whether last oration should be undone.
#
# @return [void]
def self.reload(clear_console = true, undo = false)
  # Hide warnings for already defined constants.
  verbose = $VERBOSE
  $VERBOSE = nil
  Dir.glob(File.join(PLUGIN_ROOT, "**/*.{rb,rbe}")).each { |f| load(f) }
  $VERBOSE = verbose

  # Use a timer to make call to method itself register to console.
  # Otherwise the user cannot use up arrow to repeat command.
  UI.start_timer(0) { SKETCHUP_CONSOLE.clear } if clear_console

  Sketchup.undo if undo

  nil
end

After having called this once I just press Arrow Up and Enter in the console a bunch of times while testing.

1 Like