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.
    • 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
                            • T Offline
                              todd burch
                              last edited by

                              It's not that XML is better or JSON is better. Forward thinking, XML is what I chose to use.

                              XML does, however, interface with the rest of the world better than JSON.

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

                                @unknownuser said:

                                @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

                                ok, i get this.
                                But different browsers have different ways to parse XML data.
                                What kind of code do you use so each browser can handle the xml?
                                In my case i want to import an xml.
                                So i parse it with the webbrowser of the webdialog. But due to the several possible browsers (IE 5-6-7, Safari, FF, ...) this is so difficult to manage.
                                Do you have a cross browser script that reads XML files?

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

                                  @pout said:

                                  But due to the several possible browsers (IE 5-6-7, Safari, FF, ...) this is so difficult to manage.

                                  IE and webkit is the only options.

                                  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

                                    Hey ThomThom,

                                    Can you explain a bit more?
                                    Thx

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

                                      With Webdialogs you only deal with IE (under Windows) and webkit (under OSX). All other browsers are irrelevant.

                                      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

                                        @unknownuser said:

                                        It's not that XML is better or JSON is better. Forward thinking, XML is what I chose to use.

                                        XML does, however, interface with the rest of the world better than JSON.

                                        Comparison between XML and JSON: http://en.wikipedia.org/wiki/Json#XML

                                        Pout, Google LoadXML (for Windows) and DOMParser for Safari.

                                        Or, see these links:

                                        http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.loadxml.aspx
                                        http://www.w3schools.com/dom/dom_parser.asp

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

                                          Todd,

                                          Tll now i was using:

                                          xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                                          xmlDoc.async="false";
                                          xmlDoc.onreadystatechange = readXML;
                                          xmlDoc.load(url);
                                          
                                          function readXML()
                                          {
                                             if(xmlDoc.readyState == 4)
                                             {
                                          	_extractxml();
                                          	}
                                          }
                                          

                                          for windows/IE, did work, but also show script time execution errors.
                                          Let's see if LoadXML is better

                                          Thanks for the links! Much appreciated

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

                                            I got LibXML-Ruby working with SU.
                                            What I needed to get it working was:
                                            Get http://rubyforge.org/frs/download.php/53633/libxml-ruby-1.1.3-x86-mswin32-60.gem
                                            From lib folder
                                            libxml folder
                                            xml folder
                                            libxml.rb
                                            xml.rb
                                            From ext/mingw folder
                                            libiconv-2.dll
                                            libxml_ruby.so
                                            libxml2-2.dll
                                            From Ruby folder:
                                            stringio.rb
                                            zlib1.dll

                                            I succeeded parsing a big file, although I couldn't parse multiple files in a row.
                                            The problem is when I parse 4 files in a row, libxml stucks while creating the Document object.

                                            LibXML::XML::Document.new(file).root

                                            And it gets non-responsive. Also it blocks the SU process and it doesn't finish when I close SU.

                                            I also didn't get any times to compare rexml and libxml running over SU.

                                            If anybody has any hints to my problem, I would appreciate it. Right now I am trying to compile libxml-ruby and set up some breakpoints so I can see where it is halting the execution.

                                            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