August 12, 2011

Install rbclipper in Sketchup 8

Sketchup doesn't support ruby gems. In some cases it is possible to move the content of a gem into a Sketchup installation to use it. I installed the excellent Clipper library by Angus Johnson. Mike Owens have made a ruby binding rbclipper, that I installed like this:
  • install ruby and devkit as in Compile C++ plug-in for Sketchup.
  • open a shell window with DevKit/msys.bat
  • run the command
    • gem install clipper
  • copy the file clipper.so to the sketchup plugins directory - in my case i copied C:\Ruby187\lib\ruby\gems\1.8\gems\clipper-2.9.0\lib\clipper.so to C:\Program Files\Google\Google SketchUp 8\Plugins
  • test by running the following ruby commands in the sketchup ruby console

    require 'clipper'
    a = [[0, 0], [0, 100], [100, 100], [100, 0]]
    b = [[-5, 50], [200, 50], [100, 5]]
    c = Clipper::Clipper.new
    c.add_subject_polygon(a)
    c.add_clip_polygon(b)
    c.union(:non_zero, :non_zero).inspect

  • the result should be 
    • [[[100.0, 0.0], [100.0, 5.0], [200.0, 50.0], [100.0, 50.0], [100.0, 100.0], [0.0, 100.0], [0.0, 50.0], [-4.999999, 50.0], [0.0, 47.8571432653061], [0.0, 0.0]]]

Compile C++ plug-in for Sketchup

Sketchup crashes when loading a C++ ruby extension. As Dan Rathbun says in for example http://forums.sketchucation.com/viewtopic.php?f=180&t=34735#p306377, you have to compile the extension using ruby 1.8. This solved my problem - I had used ruby 1.9 when I experienced my crashes.

I failed to find a complete how-to for successfully compiling an extension for Sketchup, so here is how I did:
  • now you should have mytest.so in the current directory
  • copy mytest.so to the sketchup Plugins folder - in my case C:\Program Files\Google\Google SketchUp 8\Plugins
  • start sketchup
  • use menu Window/Ruby Console
  • in the ruby console edit field do as the rubyinside.com/how-to... page says:
    • require 'mytest'
    • include MyTest
    • puts test1
  • the last command should print 10