Require rubygems in SketchUp


#1

I have been trying to find out searching online how to require rubygems
in SketchUp, but have been unable to find out specifically how.

Below is my plugin in C:\Program Files\Google\Google SketchUp 8\Plugins\gems.rb:

   $: << 'C:/Ruby186/lib/ruby/site_ruby/1.8'
$: << 'C:/Ruby186/lib/ruby/site_ruby/1.8/i386-msvcrt'
$: << 'C:/Ruby186/lib/ruby/site_ruby'
$: << 'C:/Ruby186/lib/ruby/1.8'
$: << 'C:/Ruby186/lib/ruby/1.8/i386-mingw32'
$: << '.'
require 'rubygems'

And I got the following error:

Error: #<LoadError: C:/Ruby186/lib/ruby/1.8/i386-mingw32/thread.so: 127: The specified procedure could not be found.   - C:/Ruby186/lib/ruby/1.8/i386-mingw32/thread.so>
(eval):14
C:/Ruby186/lib/ruby/1.8/thread.rb:5
C:/Ruby186/lib/ruby/site_ruby/1.8/rubygems.rb:11:in `require'
C:/Ruby186/lib/ruby/site_ruby/1.8/rubygems.rb:11
(eval):14:in `require'
(eval):14

However, thread.so is exactly in C:/Ruby186/lib/ruby/1.8/i386-mingw32:

C:\Ruby186\lib\ruby\1.8\i386-mingw32>ls
Win32API.so    digest.so      fcntl.so   openssl.so   sdbm.so      version.h
bigdecimal.so  dl.h           gdbm.so    racc         socket.so    win32
config.h       dl.so          iconv.so   rbconfig.rb  st.h         win32ole.so
curses.so      dlconfig.h     intern.h   re.h         stringio.so  zlib.so
dbm.so         dln.h          io         regex.h      strscan.so
defines.h      enumerator.so  missing.h  ruby.h       syck.so
digest         env.h          nkf.so     rubyio.h     thread.so
digest.h       etc.so         node.h     rubysig.h    util.h

Trying to test in SketchUp Ruby Panel:

> require 'bigdecimal'
true
> require 'curses'
true
> require 'dbm'
true
> require 'digest'
true
> require 'digest/md5'
Error: #<LoadError: C:/Ruby186/lib/ruby/1.8/i386-mingw32/digest/md5.so: 126: The specified procedure could not be found.   - C:/Ruby186/lib/ruby/1.8/i386-mingw32/digest/md5.so>
(eval):14
(eval):14
> require 'digest\md5'
Error: #<LoadError: C:/Ruby186/lib/ruby/1.8/i386-mingw32/digest\md5.so: 126: The specified procedure could not be found.   - C:/Ruby186/lib/ruby/1.8/i386-mingw32/digest\md5.so>
(eval):14
(eval):14
> require 'digest/sha1'
Error: #<LoadError: C:/Ruby186/lib/ruby/1.8/i386-mingw32/digest/sha1.so: 126: The specified procedure could not be found.   - C:/Ruby186/lib/ruby/1.8/i386-mingw32/digest/sha1.so>
(eval):14
(eval):14
> require 'digest\sha1'
Error: #<LoadError[:][1] C:/Ruby186/lib/ruby/1.8/i386-mingw32/digest\sha1.so: 126: The specified procedure could not be found.   - C:/Ruby186/lib/ruby/1.8/i386-mingw32/digest\sha1.so>
(eval):14
(eval):14
> require 'digest\sha2'
true
> require 'digest/sha2'
true

2 Questions

Why some of files in C:/Ruby186/lib/ruby/1.8/i386-mingw32 can be required correctly, while some can’t and prompt LoadError?Why the last two lines return both true? Does is has something to do with the loading problem?

Environment

Windows 7
Ruby 1.8.6
SketchUp 8.0.14346


#2

SketchUp did not support RubyGems in SU 8, so don’t expect any official help from Trimble (in fact, no Ruby standard libraries were distributed with SketchUp 8). Also, SketchUp has always shipped with its own specially-built version of the Ruby interpreter; it does not use the system-installed Ruby. As a result, the SketchUp Ruby does not always play nicely with the system libraries.

Bottom line: you are into hacking SketchUp and unless another hacker has tried what you are doing, you are on your own! Sorry!


#3

As of SketchUp 2014 we ship with Ruby 2.0 and the StdLib.

For SU to use the StdLib with Ruby 2.0 we had to do some initialization to get everything set up correctly. Might be something similar in 1.8.

Is there any reason that makes it a must for you to use older SketchUp version which uses Ruby 1.8 (which has reach end of life btw)?


#4

b[/b] The main issue is that you installed the minGW compiled Ruby instead of the Visual Studio installed Ruby 1.8.6-p287.

The error you see (I believe,) indicates this fact. (The text messages for load exceptions are somewhat cryptic when it comes to incompatible files.)

I packed the latter as an “experimental” SketchUp extension rbz archive (which properly installs into SketchUp’s “Plugins” directory, so as NOT to conflict will a computer’s “System Ruby install”, which uses the paths you tried to, as is likely to be at some version level above 2.0 [as all lower versions are beyond EOL and no longer supported or patched.])
See: https://github.com/DanRathbun/sketchup-ruby186-stdlib-extension/releases


b[/b] Noone ever got RubyGems to work well enough, in the Ruby 1.8.x branch, to enable non-gurus (ie, your average non-IT technician / SketchUp user,) to be able to install it, much less rely upon it.

As an example, you cannot rely upon that a user’s machine will have the correct compilation environment (files, etc.) to install gems that are not pre-compiled.

This really means that it is much easier to distribute only pure-Ruby gems and pre-compiled gems, by repackaging them into proper SketchUp extension archives.

As long as…


b[/b] Unicode string support (especially in pathstrings on PC,) is basically non-existent in Ruby 1.8.x.

TIG did write a rudimentary string converter library. It is posted over at SketchUcation.


As a result of the above issues,… and because RubyGems is now packaged with the Ruby Standard library (since perhaps Ruby 1.9.2 ?, or there about,) and because of Ruby 2.x’s built-in Unicode string support [needed because many non-English usernames have Unicode characters in them, and these names are part of the path strings into the user folders,] … many developers are quickly dropping SketchUp plugin support for SketchUp 2013 and earlier.

When SketchUp 2016 comes out, I’ll myself will be uninstalling SU8 and SU2013 (which use Ruby 1.8,) and never again writing or testing any plugins under or for those versions.


bbCode has stopped rendering in the forum posts
#5

Also be aware that the paths in rbconfig.rb (even in the latest SketchUp,) refer to the computer on which Ruby was compiled,… and not to the special location of where SketchUp’s “embedded” Ruby library is located.


#6

Is there an example on how to require ImageMagick so it can be used inside SkectchUp?

Thanks in advance!


#7

Just to clarify, do you want to require RMagick?

With current Ruby versions in use in SU, it might be tricky. ImageMagick is available as a package that can be used to build the RMagick gem in Ruby 2.4+. So, if the next version of SU updates to Ruby 2.4+, you probably could load it.

Greg


#8

Using gems in SU is a bit tricky. If you try to use the gem system to install it on the user machines you might have issues if it needs to be compiled. Then if it works, the installation experience might be jarring for the user, as some gem installations might freeze SU for a while, making users think SU have hung.

If all that works, you have potential of clashing with other extensions if they also try to use the same gem, but using a different version. The gem system isn’t ideal in a shared environment like SU. It was intended for environments where a single developers controls the whole environment.

By recommendation if you need gem functionality is to fork it and make it part of your own extension namespace. Then you ship the whole “gem” as part of your extension.