How to load the system lib of ruby for SU
-
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 -
- 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:ineach' C:/SketchUp/Plugins/rexml/document.rb:175:in
write'
C:/SketchUp/Plugins/PhysicalSiteXMLWriter.rb:371:in `savePhysicalSiteToFile'
(eval):676 -
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.
-
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.closeThe 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. -
SketchUp currently uses Ruby v1.8.6-p287
Ruby (v1.8.6-p287) Windows One-Click InstallerStandard 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.
Advertisement