sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    How to load the system lib of ruby for SU

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 217 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.
    • Q Offline
      qiucx
      last edited by

      I am developing a plugin which is used to load the model of SU to xml file. In my Myplugin.rb file, the lib under Ruby193\lib\ruby\1.9.1\rexml is used, i am sure that my Myplugin.rb can work correctly in RubyMine IDE, however, when starting SU 8.0 to load plugin, error occurs caused by failing to load 'rexml/document', how to solve it? thanks.

      Any help is appreciated.

      Myplugin.rb:

      require 'rexml/document'
      require 'rexml/text'
      require 'entities'
      include REXML

      1 Reply Last reply Reply Quote 0
      • Q Offline
        qiucx
        last edited by

        1. If i copy the rb files from version 1.8.6 to plugin folder in SU, i will have the error as following, why doesnot the SU support ruby api 1.8.6? How to do it?

        w = PhysicalSiteXMLWriter.new()
        #PhysicalSiteXMLWriter:0xd56eac0
        p = PhysicalSite.new
        #PhysicalSite:0xcd8951c
        w.savePhysicalSiteToFile(p, 'aaaa.xml')

        Error: #<NoMethodError: undefined method <<' for #<Sketchup::Console:0xccbcc4c>> C:/SketchUp/Plugins/rexml/element.rb:676 C:/SketchUp/Plugins/rexml/document.rb:177:in write'
        C:/SketchUp/Plugins/rexml/document.rb:175:in each' C:/SketchUp/Plugins/rexml/document.rb:175:in write'
        C:/SketchUp/Plugins/PhysicalSiteXMLWriter.rb:371:in `savePhysicalSiteToFile'
        (eval):676

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          SketchUp Ruby isn't fully compatible with the Standard Library.

          The Set class is incompatible and in your case it appear there are conflicts with use of stdout - where Sketchup::Console (which feeds the output to the SketchUp Ruby Console) doesn't support the methods REXML tries to use.

          Btw, REXML is probably the slowest XML package out there. Really slow.

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • Q Offline
            qiucx
            last edited by

            Thanks for your reply.

            I solve this problem using the version 1.8.6 ruby and copying the rexml folder to plugins. As pointed by TT, the compatiblity is not good. the following code does not work:

            # Write the xml to file.
            #formatter = Formatters::Pretty.new(2)
            

            formatter.compact = true

            #File.open(path, 'w') { |result| formatter.write(doc, result) }

            and after changing to the following, it works:

            file = File.new(path,"w+")
            file.write(doc.to_s)
            file.close

            The reason is that the element.rb is not powerful so that the write function of document does not work.
            After converting the XML to string and write via File class, it works.

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              SketchUp currently uses Ruby v1.8.6-p287
              Ruby (v1.8.6-p287) Windows One-Click Installer

              Standard Ruby Library folders DO NOT belong in SketchUp's "Plugins" folder.
              They belong in the Standard Ruby Library folders.

              Once a user installs the full Ruby edition, SketchUp's Ruby can access it's library folders, by pushing library paths into SketchUp's **$LOAD_PATH** array.

              See: [ Code ] Ruby LOAD PATHs script (Win32)

              💭

              I'm not here much anymore.

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

              Advertisement