by Dan Rathbun » Wed Jul 28, 2010 9:10 pm
Ruby LOAD PATHs script for Win32 SummaryRuby has Extended classes and modules that can be loaded when needed by using the require('libfilename') method. In order to use Ruby Extended Library files you must have a full Ruby install on your system. Win32 Sketchup comes only with the Ruby interpreter. Windows does not come "out-of-the-box" with a full Ruby Installation (as most Unix-like systems do.) On Windows, you need to go get the Ruby v1.8.6-p287 Windows One-Click Installer (self-extracting zip installer,) to install Ruby on your system. Once installed you must tell Ruby where to look for the libraries. This script will add the paths to the library folders into the global $LOAD_PATH array. See the Reference posts on how to copy the interpreter DLL into the Sketchup program folder. Reference ChangeLogVersion: 3.0.1- fixed line15: ver=RUBY_VERSION.split('.')[0..1].join('.')
- was: ver=RUBY_VERSION.split('.')[0..1].join
Version: 3.0.0 - Changed pre and ver variable settings to be more automatic & more version agile.
- Thanks go to Jim Foltz for pointing out the need for these changes.
Version: 2.0.1 - Changed ver reference to use constant RUBY_VERSION.
Version: 2.0.0 - Wrapped console output in a 1 sec delay timer, so it can get caught by the console during Sketchup startup.
- Added variable cleanup at end.
Version: 1.0.0 - originally posted at SCF and GoogleGroups buried deep inside other topics (where you might not find it.)
Code- Code: Select all
# file: '!loadpaths.rb' # for Win32 # # Version 3.0.1 - Public Domain # # Authored by : Dan Rathbun # Contributors : Jim Foltz # begin # # TWEEKER variables # # may change 'ver' to a literal string if RUBY_VERSION < '1.9.0' ver=RUBY_VERSION.split('.')[0..1].join('.') else ver=RUBY_VERSION end # # 'pre' is the rubylib path prefix pre='C:/ruby'<<RUBY_VERSION.split('.').join<<'/lib/ruby' # plat=RUBY_PLATFORM # # add the standard lib path $LOAD_PATH << "#{pre}/#{ver}" # add the standard platform sub lib path $LOAD_PATH << "#{pre}/#{ver}/#{plat}" # # optionally add paths to vendor_ruby libs # only apply if there are things installed there #$LOAD_PATH << "#{pre}/vendor_ruby/#{ver}" #$LOAD_PATH << "#{pre}/vendor_ruby/#{ver}/#{plat}" # # optionally add paths to site_ruby libs # only apply if there are things installed there #$LOAD_PATH << "#{pre}/site_ruby/#{ver}" #$LOAD_PATH << "#{pre}/site_ruby/#{ver}/#{plat}" # $LOAD_PATH.uniq! # # print LOAD PATHS to console # (May not print during Sketchup startup!) Sketchup.send_action('showRubyPanel:') UI.start_timer(1,false) { puts "\nLOAD PATHS:\n" $LOAD_PATH.each {|x| puts "#{x}\n"} puts "\n\n" } # end # cleanup ver=nil pre=nil plat=nil GC.start # # end of '!loadpaths.rb'
Cross-Platform IssuesAnyone want to make a Mac version out of this?I'm not sure but, I think on OSX the pre variable would be set: pre='/usr/local/bin/ruby'<<RUBY_VERSION.split('.').join<<'/lib/ruby'Can any Mac OSX users verify ??
COMMUNITY CONTENT - Public Domain - Author claims no copyright. Moderators may edit post / correct code snippet(s) at will.
Last edited by Dan Rathbun on Tue Aug 09, 2011 2:16 am, edited 8 times in total.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Jim » Fri Jul 30, 2010 4:42 pm
Dan, With the new installers, the install path has changed slightly from what is in your code. And it is possible to have multiple installs. I have both 1.8.6 and 1.9.1 installed on Windows XP. The paths are: C:\Ruby186\ C:\Ruby191\ See image:
Hi
-
Jim
- Global Moderator
-
- Posts: 4678
- Joined: Mon Nov 12, 2007 10:13 pm
- Location: ohio
- Name: Jim
- Operating system: Windows
- SketchUp version: 2017
- License type: Pro
- SketchUp use: hobby
- Level of SketchUp: Intermediate
-
by Dan Rathbun » Fri Jul 30, 2010 7:54 pm
Yes.. well that's why I put the 3 "tweeker" vars at the top of the script. Makes it easier to "tweek" to your system. If you run standard ruby (outside of Sketchup,) the $LOAD_PATH should be set for each version for you. If Not, you should use pik (Win32) or RVM (OSX,Linux,etc.) to switch between versions (or even patchlevels.) Presently Sketchup cannot load v1.9.1 (or higher,) but let's say your example showed v1.8.6 and v1.8.7 installs. A user of the above script would need to "tweek" the pre var (which is short for 'prefix'.) On Win32 they'd need to shuffle msvcrt-ruby18.dll files around either manually or via batch script. The pre var could be set automatically inside Sketchup by changing the reference assignment to: pre='C:/ruby'<<RUBY_VERSION.split('.').join<<'/lib/ruby'I noticed also the lib dir is "1.8" instead of "1.8.6" (I swear the old 1.8.6-p26 had it as "1.8.6"... but I've long since uninstalled it.) So the ver var needs a bit of work. CODE SNIPPET (above) EDITED and UPDATED to 3.0.0
Last edited by Dan Rathbun on Sat Jul 31, 2010 2:27 am, edited 1 time in total.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Dan Rathbun » Sat Jul 31, 2010 2:26 am
Dan Rathbun wrote:Anyone want to make a Mac version out of this?
I'm not sure but, I think on OSX the pre variable would be set: pre='/usr/local/bin/ruby'<<RUBY_VERSION.split('.').join<<'/lib/ruby'Can any Mac OSX users verify ??
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Dan Rathbun » Sat Jul 31, 2010 11:36 pm
UPDATED: fixed silly mistake in line 15 ver now is: 3.0.1
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by thomthom » Sun Aug 01, 2010 9:29 pm
Sorry, but what does this do? I see a title and changelog, but no summary.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Dan Rathbun » Mon Aug 02, 2010 11:47 am
thomthom wrote:I see a title and changelog, but no summary. You are right! I moved this code from where it was buried down deep in a discussion thread, to it's own topic so it could be mantained and found more easily. But that took it out of context. (Shame on me.) The post looks a bit more profesional now. .. thanks for keepin' me on my toes, Thomas.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by thomthom » Thu Aug 05, 2010 5:18 pm
This looks handy for testing out full Ruby with SU. 
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Dan Rathbun » Thu Aug 05, 2010 5:54 pm
thomthom wrote:This looks handy for testing out full Ruby with SU. 
That IS the idea. Instead of copying standard library files by ones or twos into some plugin folder (which may differ in version to the interpreter your running with Sketchup,) the idea is to leave those library files where they are (so they can be managed and maintaned with RubyGems.) This script then allows you to just load them from your (or a user's,) full install folders. That way we won't have old versions of standard library files, peppered amonst our plugin subfolders.
The next step in revising this script is to allow for alternate install locations, if a user is using concurrent version managment software ( pik on Win32, RVM on OSX.) I'll have to add a " base" variable that replaces the "C:/" in the pre variable with "#{ENV['USERPROFILE']}/.pik/" (Win32) or "#{ENV['HOME']}/.rvm/" (OSX). And perhaps a custom base location var.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Dan Rathbun » Wed Dec 29, 2010 2:00 pm
replying to: Re: Clients <--> Server Communication (Sockets?)mtalbott wrote:Jim, that's Interesting. At first I couldn't replicate your require 'socket' result but then I tried in Sketchup 8 and it worked. "RUBY_VERSION" in SU7 says "1.8.0" and in SU8 "1.8.6" Is that why it doesn't work in 7?
No. It's because you used an absolute path to the socket.so file, and your system was able to find it. mtalbott wrote:i386-mingW32 vs i386-mswin32 is beyond me at the moment. RUBY_PLATFORM is the constant, set by the compiler that complied the Ruby that is running. In Sketchup, open the Console and type RUBY_PLATFORM, do the same (outside Sketchup,) in IRB for one of the Standard Ruby installs... you'll see the value is different. i386-mswin32 is compiled with MS Visual Studio i386-mingW32 is compiled with the minGW compiler. It's not just the interpreter DLL that is compiled, all of the .so ( source object,) files in the libraries are also. mtalbott wrote:I can say however, that I use your !loadpaths.rb which adds the i386-mswin32 directory to the $LOAD_PATH ...
It actually adds the ruby lib folder and the platform subfolder of the ruby lib folder to the $LOAD_PATH array, based upon the values of the RUBY_PLATFORM constant, the RUBY_VERSION constant of the interpreter that is loaded; plus a few tweeker variables, to guess at what the Standard Ruby paths SHOULD be. The script is quick and dirty.. and does not have error checking, and assumes the user knows how to use a full Ruby install, and installed it correctly. I am working on a more advanced version, that will be cross-platform, and be compatible with multiple Ruby installs managed by a RVM utility. mtalbott wrote: ... and when I "require 'C:/ruby186/lib/ruby/1.8/i386-mingw32/socket'" it returns true.
It returns true (again,) because you used an absolute path, and did NOT rely upon the $LOAD_PATH array. (You should read the description of the Kernel.require method.) mtalbott wrote:Are you recommending that I uninstall my current ruby build and get the mswin32 version?
You should endeavour to use compiled libraries that match the interpreter that is loaded, with respect to RUBY_VERSION, RUBY_PATCHLEVEL and that are compiled by the same compiler. How many Ruby versions you have, and where you put them depends on what you do with them. (There are a handful of environment vars that need to change, depending on which version you have in use.) It's easier to manage multiple installs if you use an RVM (Ruby Version Managment,) utility. I have come to believe that the Ruby Libraries used with Sketchup should be separate from those used as a "System" Ruby (which a user might use for Ruby on Rails, or major projects, or with other Applications.) This will allow the "Sketchup Ruby Install" to be tweeked for use with Sketchup, while leaving the System Ruby Install(s) alone, or to be tweeked for Rails, or whatever. For instance... I have a complete Ruby (manual) install beneath my Sketchup application folder. mtalbott wrote:Should I stick with 1.8.6?
Well ... - Sketchup will not load 1.9.x, so thats out.
- Ruby ver 1.8.0 thru 1.8.5 (all patchlevels,) are obsolete
- It may be that v1.8.7 header files did not change (from 1.8.6,) as loading up to the lastest patch (v1.8.7p330) seems to work at first blush.
- Since SU 8 is complied with MS Visual Studio, and it's Ruby API extensions are also, AND in doing so, Google had to "include" ruby header files from 1.8.6 (p287 to be exact,) I would say, it's safest to use i386-mswin32 compiled binaries in the 1.8.6 branch, of no less than patchlevel 287. If you are writing plugins that others will use, you might as well, use the version they are going to be running your plugin on.
Now.. there are certain areas (speed, stability, threads) that minGW compiled Ruby is supposed to be better than mswin32 Ruby. I tried loading a mingw Ruby interpreter and Sketchup didn't have a problem with it. The only way to tell is to use it and exercise it under sketchup and see if there are problems. For SU 7.x, I've been running it with Ruby 1.8.6-p111 or higher since the second day I had it. I always encourage ppl to replace the SU7 DLL with a Ruby 1.8.6 (I posted them for download in the Ruby Resources topic, with Instructions.)
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by mtalbott » Wed Dec 29, 2010 8:33 pm
Wow! So helpful! I'm going to have to absorb this all for a little while. Thanks.
-
mtalbott
-
- Posts: 30
- Joined: Fri Nov 06, 2009 12:50 am
- Name: mtalbott
by psylus » Thu Jul 14, 2011 4:06 pm
Hello,
I am trying to write a plugin for sketchup 8 using rubygems. I gave up trying on mac and now I'm trying on windows. I had the loadpaths script on sketchup's plugins directory. my ruby directory is C:\Ruby187, I forgot to change ruby to Ruby inside the script.
The weird thing is that even when I remove from the directory the plugin I am trying to load, I still get load error messages about it and the mistaken load path remains when I remove the loadpaths script. I tried reinstalling sketchup, delete everything from win registry, app data folders, environment variables and I still get the same error message about loading the plugin! Where is all this info stored and I can not get rid of it?
About the initial load error now, whenever I uncomment the #$LOAD_PATH << "#{pre}/site_ruby/#{ver}" line (the directory containing the rubygems file among others), sketchup crashes during launch.
I would appreciate your help, thank you in advance!
-
psylus
-
- Posts: 1
- Joined: Thu Jul 14, 2011 3:32 pm
by Dan Rathbun » Mon Jul 18, 2011 4:37 am
psylus wrote: ... my ruby directory is C:\Ruby187, I forgot to change ruby to Ruby inside the script.
Windows is a case-insenstive OS. It doesn't matter whther the 'R' in Ruby is upcase or downcase. However, if you are going to use v1.8.7 (at some patch level,) Ruby with Sketchup, you should be sure that Sketchup loads the same version and patchlevel interpreter DLL. See viewtopic.php?f=180&t=10142&p=298780#p276047 for instructions on Windows, for how to make Sketchup load another Ruby version.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Dan Rathbun » Mon Jul 18, 2011 4:57 am
psylus wrote: I am trying to write a plugin for sketchup 8 using rubygems.
...
About the initial load error now, whenever I uncomment the #$LOAD_PATH << "#{pre}/site_ruby/#{ver}" line (the directory containing the rubygems file among others), sketchup crashes during launch.
The topic of RubyGems under Sketchup embedded Ruby, belongs in the following forum thread: Getting SketchUp to play nicely with RubyGems?... I begin answering in that thread, here: viewtopic.php?f=180&t=29544&p=342469#p342469
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Dan Rathbun » Mon Jul 18, 2011 5:00 am
psylus wrote: The weird thing is that even when I remove from the directory the plugin I am trying to load, I still get load error messages about it and the mistaken load path remains when I remove the loadpaths script. I tried reinstalling sketchup, delete everything from win registry, app data folders, environment variables and I still get the same error message about loading the plugin! Where is all this info stored and I can not get rid of it?
We cannot help you unless you post the exact LoadError message. (Which will tell us the name of the script that is still trying to load the removed plugin.)
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by 26delta » Sun May 27, 2012 11:42 pm
Message from 000_AdditionalPluginFolders
2 ERROR(S): The following plugins ha errors and may not be fully loaded
PLUGIN: win32api.so FOLDER: C:\Program Files\Google\Google SketchUp 8\Plugins ERROR: 127: The specified procedure could not be found - Init_win32api C:\Program Files\Google\Google SketchUp 8\Plugins\win32api.so
PLUGIN: win32api.so FOLDER: C:\Program Files\Google\Google SketchUp 8\Plugins ERROR: 127: The specified procedure could not be found - Init_win32api C:\Program Files\Google\Google SketchUp 8\Plugins\win32api.so
-
26delta
-
- Posts: 6
- Joined: Sun Nov 28, 2010 3:19 pm
- Location: Auckland, New Zealand
- Name: Michael Mohr
- Operating system: Windows
- SketchUp version: 2015
- License type: Free/Make
- SketchUp use: historical reconstruction
- Level of SketchUp: Intermediate
-
by Dan Rathbun » Mon May 28, 2012 1:58 pm
The init function name is capitalized the same way the filename is.
Therefor you MUST call require with the so file cap'd as it is in a directory listing:
require("Win32API") # not "win32API" nor "win32api"
Last edited by Dan Rathbun on Wed May 30, 2012 2:05 am, edited 1 time in total.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by 26delta » Tue May 29, 2012 10:01 pm
Dan Rathbun wrote:The init function must is capitalized the same way the filename is.
Therefor you MUST call require with the so file cap'd as it is in a directory listing:
require("Win32API") # not "win32API" nor "win32api"
This creates an interesting problem. The error was introduced by the Rayelectron package which works with a file named "win32api.so". Somehow, in all the confusion, my Win32API.so file got overwritten by win32api.so. The files are identical, but differently named.
-
26delta
-
- Posts: 6
- Joined: Sun Nov 28, 2010 3:19 pm
- Location: Auckland, New Zealand
- Name: Michael Mohr
- Operating system: Windows
- SketchUp version: 2015
- License type: Free/Make
- SketchUp use: historical reconstruction
- Level of SketchUp: Intermediate
-
by Dan Rathbun » Wed May 30, 2012 2:17 am
26delta wrote:This creates an interesting problem. The error was introduced by the Rayelectron package which works with a file named "win32api.so". Somehow, in all the confusion, my Win32API.so file got overwritten by win32api.so. The files are identical, but differently named.
Obviously the problem was created by whomever in the "Rayelectron" project, decided it would be a good idea (NOT!) to create an extension with the same name as a standard Ruby library source object file. (Because most Operating Systems are case-aware, but case tolerant... the OS will treat the filename the same, no matter how a command or shortcut may have the text 'cased'.) BUT.. internally, the require method (for some reason...,) will only load a file if it matches casewise the part of function name following "Init_" I always wondered why the programmers did not just copy the function a few times and rename it, thus: - Code: Select all
// C function Init_Win32API(){ init(); }
function Init_WIN32API(){ init(); }
function Init_win32API(){ init(); }
function Init_win32api(){ init(); }
The only good thing from this is that a hacker/pirate cannot "steal" (violate copyright,) an so file by renaming it. ~
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|