• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

SU ruby questions part2

Scheduled Pinned Locked Moved Developers' Forum
8 Posts 3 Posters 969 Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    sepultribe
    last edited by sepultribe 12 Jul 2015, 06:28

    Hello once again. I'm confused about how to load ruby gems like savon or yaml from an external ruby 2.0 installation in sketchup 2014 M1. Is the $LOAD_PATH method and interpreter dll copying still needed like in older SU with ruby 1.8.7?

    Also, I saw a recommended template for ruby scripts wrapping the plugin inside a module and a singleton class. I understand the module creating a unique namespace so as not to clash with anything else, but what is the use of the singleton class?

    thanks

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 12 Jul 2015, 11:31

      @sepultribe said:

      Hello once again. I'm confused about how to load ruby gems like savon or yaml from an external ruby 2.0 installation in sketchup 2014 M1. Is the $LOAD_PATH method and interpreter dll copying still needed like in older SU with ruby 1.8.7?

      One question per thread, please. Let's talk about gems in this one.

      @sepultribe said:

      ..., but I think it's either that way (installing all required gem files inside your sketchup or plugin folder) or using an external ruby installation which will be the same version as your sketchup ruby version and editing the $LOAD_PATH variable to include that location.

      The second was true for the old SketchUp versions that used 1.8.x Ruby.

      Neither method is true any longer since SketchUp 2014. The Ruby Standard Library is now distributed with SketchUp. (It is beneath the "Tools" directory.)

      RubyGems is now distributed with Ruby 2.x.
      Pure ruby gems (or precompiled gems) can be installed under SketchUp. The gems folder where they are installed, is in the User %(#000000)[%AppData%] path.

      32-bit SketchUp w/ 32-bit Ruby 2.0:
      " %AppData%\SketchUp\SketchUp 2014\SketchUp\Gems"
      or:
      " %AppData%\SketchUp\SketchUp 2015\SketchUp\Gems"

      64-bit SketchUp 2015 w/ 64-bit Ruby 2.0:
      " %AppData%\SketchUp\SketchUp 2015\SketchUp\Gems64"

      Use something like:
      require "gemname" rescue Gem::install "gemname"
      or

      retried = false
      begin
        require "gemname"
      rescue LoadError
        Gem;;install "gemname"
        if !retried
          retried = true
          retry
        end
      end
      
      

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 12 Jul 2015, 11:43

        @sepultribe said:

        ... I'm confused about how to load ruby gems like savon or yaml ...

        yaml is an easy one because it is part of the Standard Library now included with SketchUp 2014 or higher.

        Just require it:
        require "yaml"


        Now in SketchUp 2015 64bit, I got no errors at the console with:
        Gem::install "savon"

        ... which returned an array (of these gem specifications that were installed):

        [
          #<Gem;;Specification;0x9619f3c nori-2.6.0>,
          #<Gem;;Specification;0x97050b8 rack-1.6.4>,
          #<Gem;;Specification;0x77ac360 httpi-2.4.1>,
          #<Gem;;Specification;0x6cba77c mini_portile-0.6.2>,
          #<Gem;;Specification;0x5471878 nokogiri-1.6.6.2-x64-mingw32>,
          #<Gem;;Specification;0x75a4d74 wasabi-3.5.0>,
          #<Gem;;Specification;0x6c0bad8 builder-3.2.2>,
          #<Gem;;Specification;0x71887e0 gyoku-1.3.1>,
          #<Gem;;Specification;0x77e0200 akami-1.3.1>,
          #<Gem;;Specification;0x5626f88 savon-2.11.1>
        ]
        

        .. afterward: require "savon"
        returned true

        💭

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • S Offline
          sepultribe
          last edited by 13 Jul 2015, 06:51

          Gem;;install "savon"
          Error; #<Gem;;InstallError; The 'nokogiri' native gem requires installed build tools.
          
          Please update your PATH to include build tools or download the DevKit
          from 'http://rubyinstaller.org/downloads' and follow the instructions
          at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
          >
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/defaults/operating_system.rb;12;in `rescue in block in <top (required)>'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/defaults/operating_system.rb;4;in `block in <top (required)>'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/installer.rb;244;in `call'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/installer.rb;244;in `block in run_pre_install_hooks'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/installer.rb;243;in `each'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/installer.rb;243;in `run_pre_install_hooks'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/installer.rb;209;in `install'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/dependency_installer.rb;372;in `block in install'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/dependency_installer.rb;332;in `each'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/dependency_installer.rb;332;in `each_with_index'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems/dependency_installer.rb;332;in `install'
          C;/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/rubygems.rb;526;in `install'
          <main>;in `<main>'
          -e;1;in `eval'
          nil
          

          thats what I get in SU2014 M1... not sure what they changed and it succeeds on 2015.

          EDIT: failed on latest 2015 (x86) version too. I'm on w7 x64 don't know if that's the issue...

          EDIT2: appended external ruby 2.0 paths to $LOAD_PATH (which has savon installed) and can't require or install savon still. this is very frustrating... Also tried pasting nokogiri.so to PLUGIN folder, to TOOLS folder, and several others with no success...

          EDIT3: installed devkit to ruby 2.0 external installation and added main directory to load_path but still no success.

          1 Reply Last reply Reply Quote 0
          • S Offline
            sepultribe
            last edited by 13 Jul 2015, 14:24

            went here ~> http://www.nokogiri.org/tutorials/installing_nokogiri.html#windows

            pasted this gem file into ..\AppData\Roaming\SketchUp\SketchUp 2015\SketchUp\Gems32\cache directory, renamed it to nokogiri-1.6.6.2.gem which is what sketchup is downloading and it managed to install at first glance.

            Gem.dir
            C;/Users/Popi/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Gems32
            Gem;;install 'nokogiri'
            [#<Gem;;Specification;0x6a38c0c nokogiri-1.6.5-x86-mingw32>]
            Gem;;install 'savon'
            [#<Gem;;Specification;0x4f8ba6c wasabi-3.5.0>, #<Gem;;Specification;0x52dd960 akami-1.3.1>, #<Gem;;Specification;0x6b64ea0 savon-2.11.1>]
            

            then I do this

            require 'savon'
            Error; #<Gem;;LoadError; Could not find 'nokogiri' (>= 1.4.2) - did find; [nokogiri-1.6.5-x86-mingw32]>
            

            I'm pulling my hair as I really need this to finish a project for school.

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by 13 Jul 2015, 16:14

              Try the 32-bit sketchup if you are not already using it.

              I use the 32-bit version of Ruby on my 64-bit Wondows because some gems just do not work when I tried. Nokogiri was one of them.

              Hi

              1 Reply Last reply Reply Quote 0
              • S Offline
                sepultribe
                last edited by 13 Jul 2015, 17:06

                @jim said:

                Try the 32-bit sketchup if you are not already using it.

                I use the 32-bit version of Ruby on my 64-bit Wondows because some gems just do not work when I tried. Nokogiri was one of them.

                I only used x86 versions of sketchup for my testing, as I need my plugin to work on old xp machines at school. I'm really curious how Dan managed to do it so easily on a 64-bit version of sketchup... I must be so unlucky. I'll try to install a x64 SU now and see if there's any luck...

                edit: confirm 64 bit SU15 doesnt throw error on savon install, BUT when I try to use it

                Gem;;install 'savon'
                [#<Gem;;Specification;0xaa0878c nori-2.6.0>, #<Gem;;Specification;0xaaa5334 rack-1.6.4>, #<Gem;;Specification;0x8640c00 httpi-2.4.1>, #<Gem;;Specification;0x6779d1c mini_portile-0.6.2>, #<Gem;;Specification;0x674d410 nokogiri-1.6.6.2-x64-mingw32>, #<Gem;;Specification;0x85a4ef4 wasabi-3.5.0>, #<Gem;;Specification;0x7ecf05c builder-3.2.2>, #<Gem;;Specification;0x82230dc gyoku-1.3.1>, #<Gem;;Specification;0x85b0498 akami-1.3.1>, #<Gem;;Specification;0x657d734 savon-2.11.1>]
                require 'savon'
                true
                client = Savon.client(wsdl; "http://www.w3schools.com/webservices/tempconvert.asmx?wsdl")
                response = client.call(;celsius_to_fahrenheit, message; { "Celsius" => "25" })
                 puts response.body
                response.body[;celsius_to_fahrenheit_response][;celsius_to_fahrenheit_result]
                res = response.body[;celsius_to_fahrenheit_response]
                res.each do |k,v| puts "#{k} = #{v}" end
                Error; #<TypeError; no implicit conversion of Sketchup;;Console into String>
                C;/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/logger.rb;595;in `exist?'
                C;/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/logger.rb;595;in `open_logfile'
                C;/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/logger.rb;553;in `initialize'
                C;/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/logger.rb;319;in `new'
                C;/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/logger.rb;319;in `initialize'
                C;/Users/Popi/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Gems64/gems/savon-2.11.1/lib/savon/options.rb;79;in `new'
                C;/Users/Popi/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Gems64/gems/savon-2.11.1/lib/savon/options.rb;79;in `initialize'
                C;/Users/Popi/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Gems64/gems/savon-2.11.1/lib/savon/client.rb;51;in `new'
                C;/Users/Popi/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Gems64/gems/savon-2.11.1/lib/savon/client.rb;51;in `set_globals'
                C;/Users/Popi/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Gems64/gems/savon-2.11.1/lib/savon/client.rb;15;in `initialize'
                C;/Users/Popi/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Gems64/gems/savon-2.11.1/lib/savon.rb;10;in `new'
                C;/Users/Popi/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Gems64/gems/savon-2.11.1/lib/savon.rb;10;in `client'
                <main>;1;in `<main>'
                SketchUp;1;in `eval'
                
                1 Reply Last reply Reply Quote 0
                • D Offline
                  Dan Rathbun
                  last edited by 14 Jul 2015, 01:15

                  The last error is the result of the quirky implementation of Sketchup::Console class. (It is not a subclass of IO, but should have been.)

                  Try some other way of testing your results.
                  UI.messagebox or a webdialog.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  1 / 1
                  • First post
                    1/8
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement