How to load all the ruby files?


#1

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 ?


#2

Hi!

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.

Examples:

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

Parameters:

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

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

SketchUp 6.0


#3

Thank you @kengey


#4

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

#5

Thanks @idibri


#6

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