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]]]

3 comments:

  1. Hell yeah. :D

    Thanks a lot, I didn't know it was possible!
    Under Win7, I had to :
    * Install Ruby under C:\Ruby187
    * "C:\Program Files\Ruby187" didn't work because of the whitespace
    * Launch msys.bat as administrator

    It worked like a charm.

    ReplyDelete
    Replies
    1. Fine that it worked for you!

      I have forked rbclipper and rebuilt it with newer versions of the Clipper library. Unfortunately I haven had the time to learn how to publish it as a gem. See https://github.com/dagrende/rbclipper.

      Delete
  2. Thanks Dag,

    I used these instructions on Windows 10, Sketchup 14.
    because Sketchup 14 uses a ruby2.0 I used:
    Ruby 2.0.0-p247

    i found the mscvrt-ruby2000.dll and checked it's version, so i tried the same version number for ruby...and it worked.

    I couldn't have got this far without your instructions....but now I've got clipper inside sketchup...awesome!

    ReplyDelete