Nokogiri vs SU2018

An alternative may be the REXML library that is supplied in the standard library, and is coded in pure Ruby. No need to compile anything or use gems or have your customers install gems.

http://ruby-doc.org/stdlib-2.2.4/libdoc/rexml/rdoc/index.html

http://www.germane-software.com/software/rexml/

http://www.germane-software.com/software/rexml/docs/tutorial.html

  • Note that when they show you can include the REXML module, that you ONLY do so into YOUR namespace or plugin modules, NOT into SketchUp’s main Ruby Objectspace.
2 Likes

Thank you for yor suggestion.
Please note

  1. I used roo for almost one year under SU2018 without any problem on my old PC.
  2. It seems that the a good solution could be if I upgrade to SU2019.
    This the hottest topic nowdays. I am as much confused about this as most of the average SU users.
    (I just renewed, 4 days before the announcment of the new licensing structure, my traditional supscription. )
    I have the very same problem as Michael
    Updating Licence for 2019

Thank you for suggestion.
At least rubyXL can installed after installing nokigiri in this way.

Thank you for your suggestion.
I browsed REXML library description. It seems clear to me.
However for my present problem it is not the solution.
I do not want to reinvent the wheel. i.e. to write a complete package for parsing xlsx files.

Anyway I duly noted your suggestion. Sometimes XML files are to be parsed.
Presently I have a LAZARUS program which makes the parsing of very special xml files and export them to xlsx format

1 Like

SU2021 pro vs nokogiri and rubyXL or roo

New SU major version was downloaded unfortunately the xlsx file parsing problem is back again.
(Please note that in SU2020 there was no problem at all)

In SU2021 the nokogiri gem is installed however neither rubyXL nor roo can be installed.

Pleae find below the install log for rubyXL (in case of roo the error log is very similar)

Gem.install ‘rubyXL’
Error: #<Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: C:/Users/Munka/AppData/Roaming/SketchUp/SketchUp 2021/SketchUp/Gems64/gems/nokogiri-1.10.10/ext/nokogiri

C:/Program\ Files/SketchUp/SketchUp\ 2021/Tools/bin/ruby.exe -I C:/Program\ Files/SketchUp/SketchUp\ 2021/Tools/RubyStdLib -r ./siteconf20201204-2872-kb9ke3.rb extconf.rb
extconf failedNo such file or directory - C:/Program Files/SketchUp/SketchUp 2021/Tools/bin/ruby.exe

Gem files will remain installed in C:/Users/Munka/AppData/Roaming/SketchUp/SketchUp 2021/SketchUp/Gems64/gems/nokogiri-1.10.10 for inspection.
Results logged to C:/Users/Munka/AppData/Roaming/SketchUp/SketchUp 2021/SketchUp/Gems64/extensions/x64-mswin64-140/2.7.0/nokogiri-1.10.10/gem_make.out

C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/ext/builder.rb:78:in rescue in run' C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/ext/builder.rb:77:in run’
C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/ext/ext_conf_builder.rb:48:in block in build' C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/tempfile.rb:291:in open’
C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/ext/ext_conf_builder.rb:30:in build' C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/ext/builder.rb:167:in block in build_extension’
C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/ext/builder.rb:163:in synchronize' C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/ext/builder.rb:163:in build_extension’
C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/ext/builder.rb:208:in block in build_extensions' C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/ext/builder.rb:205:in each’
C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/ext/builder.rb:205:in build_extensions' C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/installer.rb:844:in build_extensions’
C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/installer.rb:327:in install' C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/resolver/specification.rb:93:in install’
C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/request_set.rb:195:in block in install' C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/request_set.rb:183:in each’
C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/request_set.rb:183:in install' C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/dependency_installer.rb:325:in install’
C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems.rb:631:in `install’

:in `' ...

Please edit your posts and wrap error text correctly …

[How to] Post correctly formatted and colorized code on the forum?

Native gems cannot be built inside SketchUp. You must use pure-Ruby gems or pre-built gem binaries.

There are numerous topics about this in this category.

*Windows specific*

Except for possibly a very long time ago, SketchUp’s Ruby has always been a ‘mingw’ build. One can see this when typing RUBY_DESCRIPTION into the console. The description ends with [x64-mingw32]. These were compiled with either MSYS or MSYS2 gcc tools. ‘gcc’ tools are the standard tools used by many *nix OS’s.

With SU 2021, the description ends with [x64-mswin64_140]. Its Ruby is compiled with the Microsoft compile tools. This change was done due to compatibility issues, as Windows SU is also compiled with Microsoft tools.

Now, re Nokogiri and other gems (like sqlite3), the RubyGems web site shows several packages available for each version. Note that there is a version for ‘x64-mingw32’. This gem is pre-compiled for a range of Ruby versions, and works with Ruby mingw builds.

There is not an ‘mswin’ version.

Bottom line, unless one can compile the gems themselves, they cannot be used in SU 2021 and later versions…

Finally, Ruby itself is built and tested with both mingw and mswin builds. So, Ruby is supporting mswin, but very few gems do so.

SU 2021 has a dll that has an unexpected name. I’m not sure what that implies…

Anyway, you may be able to use the mingw Nokogiri version. It may not work, but it does load. Please test it, and be aware that SU may crash. I don’t have the time nor the code to test it.

Goto All versions of nokogiri | RubyGems.org, and download the most recent ‘x64-mingw32’ version (currently 1.11.0.rc3), then run

Gem.install '<full path to file>'

It installs the gem. You are running a mingw compiled gem in an mswin Ruby, which is something I have never tried…

Thank you for your reply. However I am not closer to the solution.
I have no idea what a pure ruby gem is. (I googled it but no useful link was found) I suppose I have used native gems so far. For me a gem is a black box/ or collection of useful routines with well defined interface. Please give us a clear guidence how to convert a native gem to “pure” ruby gem.
Just for background information in my SU universe every component is parametric and all the instances of a component too. These parameters are stored in an .xlsx file. If an xlsx file is can not be parsed then SU2021 can be used only as a little bit enhanced SU Viewer.

Thank you for your advice. However it does not solve my problem.
I downloaded the latest nokogiri-1.11.0.rc3-x86-mingw32.gem. It could be installed without any error message. SU2021 did not collapse.
However it is not working.
If later on various versions of rubyXL or roo were installed all of them reinstalled nokogiri-1.10.10 but rubyXL or roo were not.

@majorgyula

If you type the following in the SU Ruby console, what’s the output?

require 'nokogiri'; Nokogiri::VERSION

It consists of code all in plain text Ruby code.

You cannot. A native gem is written in C and compiled. Plain text Ruby code is interpreted.

The SketchUp API has attribute dictionaries so that parameters can be saved with the objects inside the model database.

But that aside, Nokogiri is not the only means of reading an XML file. Ruby comes with a standard library called REXML (that can read and write XML files) as well as a CSV class (that can read and write CSV files output from Excel.)

Thank you for your quick reply.
Now I understand everything but I am not happy at all.

I checked your recommendation REXML. Yes, it can read XML files,
Yes, an XLSX file is a bundle of XML files.
However REXML is very far from to fully parse an XLSX file.
Just one issue in my XLSX files formulas are heavily used to ensure that one SU component instance is just at the right location and orientation
or one component fits to another. If REXML is to be used then all the formula parsing should be written too.

Referring SU API attribute dictionaries. It is good to know. However for most of the cases they are not applicable for me. A lot of data are exported from other (lighting design) applications to an XLSX file. This xlsx file is processed in SU.

I tried it. It is very funny.
There is a nokogiri-1.10.10 directory in “c:\Users\Munka\AppData\Roaming\SketchUp\SketchUp 2021\SketchUp\Gems64\gems”
The error message is below

text:
require ‘nokogiri’; Nokogiri::VERSION
Error: #<LoadError: cannot load such file – nokogiri>
C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:92:in require' C:/Program Files/SketchUp/SketchUp 2021/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:92:in require’

:in `' SketchUp:in `eval'

Ok. It would be a good idea to clean the current (and incomplete) install. Go to:

c:\Users\Munka\AppData\Roaming\SketchUp\SketchUp 2021\SketchUp\Gems64

And delete any file or directory starting with nokogiri. Once done with that:

Download https://rubygems.org/downloads/nokogiri-nokogiri-1.11.0.rc3-x64-mingw32.gem to anywhere on your PC, then run:

Gem.install '<path to download>'

Once you do that:

require 'nokogiri'; Nokogiri::VERSION
1.11.0.rc3

I tried the same procedure with nokogiri-1.10.10-x64-mingw32.gem , and it wouldn’t install, not sure why. You’re welcome to try it, but 1.11.0.rc3 should work fine.

Sorry, I just noticed this. I said to download the most recent x64-mingw32 gem. You used the x86-mingw32 gem, which is a 32 bit gem which won’t work with SketchUp…

Thank you for your help.
Yes I did what you wrote,
nokogiri-1.11.0.rc3-x64-mingw32.gem was installed succesfully.

But it does not solve my original problem. If I try to install any xlsx parser gem such as rubyXL, roo or simple_xlsx_reader all of them install nokogiri-1.10.10 gem first
then terminates because ruby.exe is not found.

What you want to do is creating a ‘perfect storm’ of issues. I could explain them later.

Anyway, when you install whatever, you need to tell RubyGems to ignore dependencies. Without reviewing code, I’m not sure how to do that with Gem.install.

There’s RubyGems utility I wrote at:
https://raw.githubusercontent.com/MSP-Greg/SUMisc/main/su_gem.rb

You need to download the file, then load it in the SU Ruby console. Then type:

SUGem.install 'rubyXL --ignore-dependencies'

And everything should work. If the gem you use has any dependencies other than Nokogiri, you will also need to install them.

You can also forget about the su_gem.rb file and use:

Gem.install 'rubyXL', nil, {ignore_dependencies: true}