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

    SU Ruby + XML

    Scheduled Pinned Locked Moved Developers' Forum
    48 Posts 15 Posters 8.3k Views 15 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.
    • thomthomT Offline
      thomthom
      last edited by

      @unknownuser said:

      search in the gems directory for nokogiri (the lib and ext directory). you can make a test outside Sketchup and use ProcMon to look what files it loads and copy those in SU Plugins subdir

      I copied nokogiri.rb and nokogiri folder from the lib folder to the SU Plugin folder.

      When I start SU I get an error message:

      
      Error Loading File nokogiri.rb
      126; The specified module could not be found.   - C;/Program Files (x86)/Google/Google SketchUp 7/Plugins/nokogiri/1.8/nokogiri.so
      
      

      Which is strange - because the file is there; And a Console test:

      
      File.exist?('C;/Program Files (x86)/Google/Google SketchUp 7/Plugins/nokogiri/1.8/nokogiri.so')
      true
      
      

      So why it claims it's not there - I have no idea.

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

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

        @toxicvoxel said:

        Having explored a few options in the past I settled on writing a .DLL in .NET that uses the powerful XML query functionality of LINQ to to do the data crunching. By doing this you could call a simple function through COM to retrieve/update specific node and attribute values from SU Ruby. If you do not have knowledge of any of the main .NET languages you could possibly explore using IronRuby for this purpose.

        I've briefly sniffed at C# previously - but I have no idea on how to do what you suggest.

        I find it very odd that there isn't a built in XML support in Ruby considering how common XML is.

        ...maybe I can send the raw XML content to a Webdialog and have a JS parse it - feeding it back to Ruby. Not ideal - but I can't get any other solutions to work.

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

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          It's probably just a matter of getting the paths and require's right. Sometimes when require'ing a .so you might need to respect it's capitalization.

          requires dezip.so'

          require 'Dezip'

          Append your $LOAD_PATH to include the library folder:

          On windows (in SetchUp):

          $LOAD_PATH.concat eval(c:/ruby/bin/ruby.exe -e "p $:" )

          This appends the installed Ruby $LOAD_PATH to SketchUp. (Not well tested by me)

          Hi

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

            I'd like to make the lib work by not having full Ruby installed. Want to ship it as a normal SU plugin.

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

            1 Reply Last reply Reply Quote 0
            • T Offline
              toxicvoxel
              last edited by

              In basic terms this article may be helpful to explain the principle:
              http://stackoverflow.com/questions/265879/can-ruby-import-a-net-dll

              If you use IronRuby you may be able to write the XML parser .NET class by leveraging your curent ruby skills.
              (You will need to do some homework to confirm that you could make the IronRuby .NET class com-visible though.)
              Alternatively if you know java you could use J#.NET.

              1 Reply Last reply Reply Quote 0
              • tbdT Offline
                tbd
                last edited by

                I will try to look tomorrow when I get on my Windows machine and make a SU friendly package of a XML parser.

                It all depends on what XML files you need to parse - if they are static, then you can write a specific XML parser yourself and save the troubles. I wouldn't use XML for anything, hate that format 😉

                SketchUp Ruby Consultant | Podium 1.x developer
                http://plugins.ro

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

                  There are several different uses for XML I'd like to use. I like the format, maybe from working with websites...

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

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

                    @unknownuser said:

                    I will try to look tomorrow when I get on my Windows machine and make a SU friendly package of a XML parser.

                    It all depends on what XML files you need to parse - if they are static, then you can write a specific XML parser yourself and save the troubles. I wouldn't use XML for anything, hate that format 😉

                    hmm.. These XMl packages - are they PC only?

                    The nokogiri package has different packages for different platform. That could be a problem. I was hoping to find a cross platform solution. If REXML is cross platform I don't mind it's not too fast. But what troubles me with that is it's conflict with the Set class.

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

                    1 Reply Last reply Reply Quote 0
                    • tbdT Offline
                      tbd
                      last edited by

                      @thomthom said:

                      These XML packages - are they PC only?

                      almost everything that needs speed in Ruby is implemented as an extension, so it is platform dependent. some gems are precompiled (e.g. for Windows), others are in source form and compiled on user machine to gather additional speed on optimizations (e.g. Mac)

                      http://github.com/jnunemaker/happymapper sounds interesting but again, has a lot of requirements

                      SketchUp Ruby Consultant | Podium 1.x developer
                      http://plugins.ro

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

                        Seeing how getting an XML parser working I think I will go for a custom format and make a simple parser that creates nested Hashes. In fact, I have to make my own Hash object as I want to traverse the Hash in the order the items where inserted.

                        But I'd still like to be able to read XML data from SU ruby. There's some other projects I'd like to use it which involves reading existing XML based files.

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

                        1 Reply Last reply Reply Quote 0
                        • P Offline
                          Pout
                          last edited by

                          and? did you manage to get something working that could parse xml?

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

                            No - I've still not found a good solution. 😕

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

                            1 Reply Last reply Reply Quote 0
                            • AdamBA Offline
                              AdamB
                              last edited by

                              Thomthom, what do you actually want?

                              If you don't need the full DOM, then these big (often slow) XML parsers may be a hammer to crack a nut.

                              If you're just looking to use XML as a simple text mark-up of parameters etc, then writing something in Ruby that yanks out tag-value pairs would be trivial.

                              Developer of LightUp Click for website

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

                                You got a point there. It's mostly simple XML files with tags and attributes.
                                Could make a simple reader and writer. Make a custom class that holds values and attributes, read the XML file as a nested object.
                                K.I.S.S.

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

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  todd burch
                                  last edited by

                                  I write an xml file in ruby, pass it to my webdialog, and use the browser to parse the xml and generate my html table dynamically.

                                  Works awesome.

                                  1 Reply Last reply Reply Quote 0
                                  • M Offline
                                    MartinRinehart
                                    last edited by

                                    @unknownuser said:

                                    I write an xml file in ruby, pass it to my webdialog, and use the browser to parse the xml and generate my html table dynamically.

                                    Works awesome.

                                    Todd, you're working too hard. Replace the XML with JSON (no harder, may be easier in Ruby), pass it to your WebDialog and "parse the XML" is just eval( foo = json ). If json is a valid JavaScript object, even a complex one nesting arrays and other objects as properties (that in turn nest other ...), you're done.

                                    Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

                                    1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      todd burch
                                      last edited by

                                      No, I'm working smart. With what I am doing with XML, I can allow user customization of the entire dialog for table layout, ordering, field values, content, etc., and never have to touch how my ruby script generates the data again.

                                      1 Reply Last reply Reply Quote 0
                                      • P Offline
                                        Pout
                                        last edited by

                                        So you import the xml file into the webdialog and in there you parse it? With a javascript script or something else?
                                        I'm getting lost here.

                                        1 Reply Last reply Reply Quote 0
                                        • T Offline
                                          todd burch
                                          last edited by

                                          @pout said:

                                          So you import the xml file into the webdialog and in there you parse it? With a javascript script or something else?
                                          I'm getting lost here.

                                          I display a webdialog. In the webdialog, on some user action, (a javascript event), a javascript function calls a Ruby callback, which iterates over the SketchUp model and builds an XML document of it. Then, the callback finished by setting a javascript variable with the xml document. Then, back in javascript, I call the browser to parse the XML document. I then (in javascript) iterate over the parsed document to build my dynamic html <table>.

                                          Todd

                                          1 Reply Last reply Reply Quote 0
                                          • M Offline
                                            MartinRinehart
                                            last edited by

                                            @unknownuser said:

                                            a Ruby callback, which iterates over the SketchUp model and builds an XML document of it

                                            Why is XML better than JSON?

                                            Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

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

                                            Advertisement