Access Run Ruby Gems and Other Ruby Code From SU Ruby
-
As I understand it Sketchup has a builtin Ruby Interpreter and they had added some classes to manipulate objects in Sketchup.
Say I wanted to interface to an Oracle db that contained info on size and placement of objects. I already have a standard Ruby install that interfaces with Oracle. It also has several Gems installed that perform mathematical calcs on geometric objects. How can I link the 2 Ruby environment? Can I add some path info to reference the other Ruby install from SU Ruby? Can I reference the SU classes in my standard Ruby install? It there some Gem I can install to invoke SU ruby commands from a standard Ruby install? Can I add a standard Ruby install to SU?
Thanks for any insight on this.
-
Welcome Bill,
The first thing to try is append the $LOAD_PATH from the installed Ruby environment to the SketchUp environment.
If you run IRB in your installed Ruby, and enter $LOAD_PATH ($: for short), you might see something like this:
["c;/ruby/lib/ruby/site_ruby/1.8", "c;/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt", "c;/ruby/lib/ruby/site_ruby", "c;/ruby/lib/ruby/1.8", "c;/ruby/lib/ruby/1.8/i386-mswin32", "."]
But in SketchUp, the $LOAD_PATH might be something like this:
["C;/Program Files/Google/Google SketchUp 7/Plugins", "C;/Program Files/Google/Google SketchUp 7/Tools", "C;/Program Files/Google/Google SketchUp 7/Plugins/Podium", "C;/Program Files/Google/Google SketchUp 7/Plugins/Podium", "C;/Program Files/Google/Google SketchUp 7/Plugins/ruby"]
So in your SketchUp script, append the $LOAD_PATH from the installed Ruby to the $LOAD_PATH in script.
# Script.rb $LOAD_PATH.concat(["c;/ruby/lib/ruby/site_ruby/1.8", "c;/ruby/lib/ruby/site_ruby/1.8/i386-msvcrt", "c;/ruby/lib/ruby/site_ruby", "c;/ruby/lib/ruby/1.8", "c;/ruby/lib/ruby/1.8/i386-mswin32", "."])
Then see if you can require the needed libraries.
You might need to install version 1.8.0 of Ruby because that is what SketchUp uses... although I have been able to copy the msvcrt-ruby118.dll from my installed Ruby to my SketchUp directory without obvious problems. (Rename original first, of course.)
Advertisement