SU Ruby + XML
-
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.
-
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. -
@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
-
@unknownuser said:
a Ruby callback, which iterates over the SketchUp model and builds an XML document of it
Why is XML better than JSON?
-
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.
-
@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? -
@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.
-
Hey ThomThom,
Can you explain a bit more?
Thx -
With Webdialogs you only deal with IE (under Windows) and webkit (under OSX). All other browsers are irrelevant.
-
@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 -
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 betterThanks for the links! Much appreciated
-
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.dllI 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.
-
Today I finally got Nokigiri working.
Summarizing everything that I had to do:
1- First attempt with LibXML failed, parsing process was halting inside the C code of libxml-ruby.
2- Switched to Nokigiri project. It was as fast as libxml and apparently, had less dependencies.
3- First attempt with Nokigiri failed. I couldn't find ilibgcj_s.dll
4- Second attempt with libxml-ruby: Failed... I wanted to debug the dll but that was too difficult to be achieved. Also I posted on this forum asking for help.5- Still trying to solve the problem, I found out http://www.rubyinstaller.org on some random ruby-forum and got rubygems working under windows (I had never achieved that before).
6- Tried installing libxml the regular way: "gem install libxml-ruby"
7- Ran into a problem while compiling some of libxml-ruby`s dll.8- Tried installing nokogiri the regular way: "gem install nokogiri"
9- Successfully installed nokogiri.
10- Build some ruby script to run over Ruby, using Nokogiri.
11- Ran ProcessMonitor (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) and ProcessExplorer (http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) while using nokogiri objects over Ruby, so I could see what dlls it required.
11.2- Another good tool for tracing DLL dependencies is Dependency Viewer (http://www.foxprogramming.co.uk/freetools.html)12- Copied these dlls to Sketchup folder and msvcrt-ruby18.dll from Ruby/bin. Sketchup folder is equivalent to Ruby/bin for Sketchup's Ruby interpreter. (This is a guess)
13- Put everything about Nokogiri on Sketchup's Plugin Folder (so it was loaded together with sketchup)
14- Started Sketchup.
15- Got lots of errors, due to dependencies. These errors were caused because Sketchup's Ruby Interpreter is not fully equipped with everything Ruby's own interpreter has.
16- Through the error messages of Sketchup, copied the rest of the .rb's and .so's needed for Nokogiri (that were installed by default on a regular Ruby installation).
17- No more errors. Successfully instantiated a Nokogiri::XML::Document object.18- Rewrote my code so they would use Nokogiri instead of REXML.
My old parser, using REXML, was about 3 times slower than the new one using Nokogiri.
My library took 30-40 seconds to load with REXML and it takes 11 seconds to load with Nokogiri.
These weren't scientifically tests though. But they were good enough, and I measured it on at least 5 different computers.Hope this helps anyone.
-
@pedrobaracho said:
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.
Has anyone found a solution to this problem?
-
Hello all,
I am also looking at creating a plugin which will import some data from a large (5OOmb+) XML file (provided by a third Party) I have the import script written using Nokogiri but am having trouble installing it in SU's ruby. I reda through pedrobaracho's post, and will give it some more attention to see if i can figure it out, but does anyone know if an easy, preferably native way to do this import?
-
@pwatt01 said:
Hello all,
I am also looking at creating a plugin which will import some data from a large (5OOmb+) XML file (provided by a third Party) I have the import script written using Nokogiri but am having trouble installing it in SU's ruby. I reda through pedrobaracho's post, and will give it some more attention to see if i can figure it out, but does anyone know if an easy, preferably native way to do this import?
I haven't tried pedrobaracho's way yet, 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. I'm also looking into this and I haven't completely figured it out myself. Good luck
-
@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
"Just something like:
require "gemname" rescue Gem::install "gemname"
-
Thanks for that guys. I managed to get a hack working by compiling/installing onto my standalone Ruby and copying the needed Nokogiri files and folders across.
Advertisement