How to use a local ruby gem inside a Sketchup Extension

Console or code, … it doesn’t matter.

The Ruby API subcategory has numerous topic threads on gems under SketchUp …

IF (somehow) you copied a gem to the cache, then the Gem installer is supposed to use that instead of trying to download it from the gem server.

Gem::install("mygem")

The “somehow” would need to use FileUtils to copy the gem file to the cache folder.

(You might also need to provide a .gemspec file in the “specifications” folder, ie do whatever is usually done when the gem is downloaded from the gem server.)

GEM_CACHE = File.join( ENV['GEM_HOME'], 'cache' )
GEM_SPECS = File.join( ENV['GEM_HOME'], 'specifications' )

When SketchUp loads it adds the GEM_HOME and GEM_PATH variables to it’s copy of the environment.

IF the gem is installed into a sub-folder of SketchUp’s “gems” folder, then rubygems modification of Kernel.require is supposed to find and load it.

GEMS = File.join( ENV['GEM_HOME'], 'gems' )

from Thomas Thomassen on the SketchUp Development team …

2 Likes