Sketchup class load method
-
Hi guys,
I believe there may be a bug (or incorrect implementation) with the Sketchup class load method. My understanding of the Sketchup class load method is that it is modeled after the Ruby Kernel load method but designed to handle scrambled files (.rbs) as well as non-scrambled files (.rb). The problem is that it doesn't seem to behave the same in that the Kernel.load method will load a .rb file even if it is already loaded - with the appropriate warnings - wereas the Sketchup.load method does not; even when executed from the Ruby console.
For example:
Kernel.load 'cabwriter_factory_settings.rb' results in
C:/Users/Joe/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/cabwriter_factory_settings.rb:17: warning: already initialized constant CabWriterFactoryInitialize::NEW_PROJECT
C:/Users/Joe/AppData/Roaming/SketchUp/SketchUp 2015/SketchUp/Plugins/cabwriter_factory_settings.rb:17: warning: previous definition of NEW_PROJECT was here
trueWhereas Sketchup.load 'cabwriter_factory_settings' results in
false
Am I missing something or is this a bug?
-
load "some_text_file_in_the_load_path"
always returns
true
unless there is an error.require "some_text_file_in_the_load_path"
only returns
true
if that file has never been loaded before during that session.Sketchup's own
require
andload
are designed to work with text files [typically RB files] OR its specialized compiled RBS files,
OddlySketchup::load
is actually an alias ofSketchup::require
- so both of them will returnfalse
if the file has been loaded before.
So when testing use 'load
' instead !
Compile the RB to RBS if desired and use Sketchup's method to load it - only when you've debugged the code...
Advertisement