Error loading dependencies

I have encripted a new extension and it works perfectly on my mac. When I encripted and obtained my rbz file I receive this error message while I load Sketchup

Error: #<LoadError: cannot load such file -- c:/users/rafaelteresachinchil/appdata/roaming/sketchup/sketchup 2022/sketchup/plugins/skp4d/aux code/sketchup4D functions.rb>
C:/Program Files/SketchUp/SketchUp 2022/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:92:in `require'
C:/Program Files/SketchUp/SketchUp 2022/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:92:in `require'
c:/users/rafaelteresachinchil/appdata/roaming/sketchup/sketchup 2022/sketchup/plugins/skp4d/sketchup4d.rbe:4:in `<main>'
C:/Program Files/SketchUp/SketchUp 2022/Tools/extensions.rb:197:in `eval'
C:/Program Files/SketchUp/SketchUp 2022/Tools/extensions.rb:197:in `require'
C:/Program Files/SketchUp/SketchUp 2022/Tools/extensions.rb:197:in `load'
C:/Users/rafaelteresachinchil/AppData/Roaming/SketchUp/SketchUp 2022/SketchUp/Plugins/skp4D.rb:11:in `register_extension'
C:/Users/rafaelteresachinchil/AppData/Roaming/SketchUp/SketchUp 2022/SketchUp/Plugins/skp4D.rb:11:in `<top (required)>'

I have this lines in sketchup4d.rb

require 'json'
require 'sketchup.rb'
require File.join(File.dirname(__FILE__), '/aux code/sketchup4D functions.rb') #required at start

After the encription both sketchup4d.rb and sketchup4D functions.rb changed to .rbe.
Is ther any problem with spaces in files or folder names?

For encrypted rubies you must use Sketchup::require. The basic require doesn’t know about encrypted.

2 Likes

Thanks @slbaumgartner it worked!

The answer was given on this Help Center page (under the section Ruby Encryption) …


Just a note to explain that the extension registrar script and the extension subfolder should normally be a concatenation of the namespace module and the submodule (or extension name.)

So if your top level namespace module is named Rafa (just for example’s sake,) then the extension registrar script and the extension subfolder would be named …
Rafa_SketchUp4D or rafa_sketchup4d (if you’re one of those that like to downcase all files names.)

The files themselves would be module wrapped similar to …

module Rafa
  module Skp4D

    # ... All code inside the extension submodule ...

  end
end

You might as well just use the global method __dir__() since you want the current directory,
and we omit the filetype when using Sketchup::require so it can load both .rb and rbe files, ie:

Sketchup.require(File.join(__dir__, '/aux code/sketchup4D functions'))
1 Like