How to load all the ruby files?

I am new to Sketchup and developing a plugin.
I have a ruby folder in my plugins folder which will contain all the ruby scripts.
The outer ruby script which register with extension manager just loads one file.
How to load all the scripts in ruby folder ?


You can require all other ruby script files from that single file that gets loaded by the extension manager.
From the documentation:

The require method is used to include encrypted and nonencrypted ruby files. This is an alias of the Sketchup.load method.

You do not need to include the file extension on the path. This method will look for .rbe first (encrypted) and then .rbs (the deprecated scrambled format) and finally .rb (unencrypted) files. The loading order was changed in SketchUp 2016 when the new .rbe encryption was introduced. Prior to SketchUp 2016 the loading order was first .rb then .rbs.


sfile = "application_loader" # file extension not required
status = Sketchup::require(sfile)


path (String) — The path, including the filename, to the file you want to require.

(Boolean) — True if the file is included. False if the file is not included.

SketchUp 6.0

Thank you @kengey

I create loader.rb in the directory that I want to load scripts from and use this snippet:

current_path = File.dirname(__FILE__)
files_rb = Dir.glob("#{current_path}/**/*.rb*")
files_rb.delete('./loader.rb') # prevents cyclic loading
files_rb.each{|f| Sketchup.load(f) } #deals with encrypted rb files

Thanks @idibri

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.