Ruby Gems in Sketchup 2016


#1

I noticed something new about the application support folder for SU2016. We seem to have a new folder called “Gems”. On my Mac, there is this folder I have not noticed before:
~/Library/Application Support/SketchUp 2016/SketchUp/Gems

Now, I have been trying to get ruby gems working (specifically sqlite3), and I know many have struggled in the past (e.g - Cannot install ruby gem in OSX ).

I wonder if there has been work done on 2016 on ruby gems? If so, is there any more information about this new folder that might help me? I want to develop a plugin that can install sqlite3-ruby on all platforms without too much hassle.


#2

That folder, like some of the other App Support ones, gets created when needed but has been in SketchUp since version 2014.

To install a Gem into SketchUp, invoke

Gem.install "nameOfTheGem"

where, obviously, nameOfTheGem is replaced by the name of the actual Gem you want to install.

Getting a Gem to work is somewhat hit-or-miss. Some Gems install and work flawlessly. Others, particularly ones that assume Ruby is running in a console window won’t work because SketchUp doesn’t provide keyboard input and screen output the way they expect. And there are configuration issues that generally prevent installation of Gems that require local compilation of C code.


#3

@TommyK, you may be better off using the javascript version which is self contained and cross platform…

have a look at this demo

running a local copy from your plugin may be easier then using gems…

john


#4

Yes - this is the problem I ran into with sqlite3. Would you consider this a shortcoming of the gems, or of Sketchup’s implementation of Ruby? I would be interested to know, as if it’s about the gems, I might be able to fix it.

VERY interesting. Sounds like it could work well for me. I would have thought performance would take a hit compared to the C program? Even so, I think this is the only way to go for me.

Thanks for the help.


#5

Well, some of both…The problems I have encountered were at two levels.

First is SketchUp’s fault. The way that Ruby is embedded inside SketchUp is different from how it normally installs in an OS (SketchUp provides its own Ruby, it does not use the OS’s). The Gem setup data distributed with SketchUp doesn’t account for these differences, so the makefiles Gem builds inside SketchUp aren’t always able to compile (for example, Gem determinedly tried to generate 32-bit executables on my 64-bit Mac). If you can figure out the somewhat arcane build system used by Ruby Gems, you might be able to tweak the configuration data in SketchUp’s installation to let Gem create viable makefiles. I tried and gave up in frustration! Also, at least one Gem that I attempted used Ruby scripts to move files around during the build, and these failed because SketchUp does not provide a standalone Ruby interpreter in the location that the Gem installer assumed! I copied one there, and then it hit issues with improper command line syntax when launched from within SketchUp’s Gem installer.

Some people have had success with some Gems by building them using the OS’s Ruby and then copying the files over to the appropriate folders within SketchUp. It’s worth a try, but no guarantee it will succeed.

Second, some Gems try to do things that are not compatible with SketchUp. You might be able to edit the source code for these to eliminate the issues. In the earlier post I mentioned that standard input and output don’t work the way that a Gem might assume when inside SketchUp. There are also a few Ruby libraries that were removed from the SketchUp distribution or tweaked because they cause crashes. A Gem that needs them will fail, potentially without a visible error message. Multi-threading runs a risk of blocking or crashing the entire SketchUp process.

So, with all of that going on, it is very much hit-or-miss.


#6

Thank you for that explanation. I think you have safely put me off trying to get them working within an extension for distribution. That’s days of my life saved. Thanks.