LoginSignup
0
0

More than 5 years have passed since last update.

SketchUpで、Rubyの標準ライブラリを使う(OSX版)

Posted at

SketchUpに組み込まれているRubyエンジンは標準ライブラリのサブセットのため、標準ライブラリをrequireすると、no such file errorが発生します。

それを解消するためのスクリプトを紹介します。

 loadpaths.rb
    #  file: '!loadpaths.rb'
    #  for mac OS X
    #
    #  Version 3.0.1   -  Public Domain
    #
    #  Authored by  :  Dan Rathbun
    #  Contributors :  Satrex
    #
    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='/usr/local/bin/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'

このコードの出典は、以下の通りです。
http://sketchucation.com/forums/viewtopic.php?t=29412#p257058

著作権はパブリックドメインと書いてあります。
記事執筆時点(2012/12/13)で、v3.0.1です。
使用される方は、最新版を確認される事をおすすめします。

テスト環境:
OS X(10.8.2)
Rubyバージョン:1.9.3

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0