Your extension files must be in a uniquely named subfolder beneath the %AppData% "Plugins"
folder, except for the extension’s registrar script that defines a SketchupExtension
data object.
So, the registrar file is the only file that goes in the "Plugins"
folder. All other extension files (rb
, so
, dll
, image files, etc.) must go in the extension’s subfolder hierarchy.
Your extension’s registrar script and the subfolder must have the same name.
All your code must be within a unique namespace module and each extension in a submodule of your namespace module.
Let us say that your extension name is “Widget” and your namespace is “ShubHam”.
Then the extension registrar file would be "ShubHam_Widget.rb"
and the extension subfolder would be "ShubHam_Widget"
.
The code module wrapping should follow the file and folder naming …
# encoding: UTF-8
# SketchUp extension registrar file: "ShubHam_Widget.rb"
module ShubHam
module Widget
EXTENSION = SketchupExtension.new("Widget", "ShubHam_Widget/loader")
EXTENSION.instance_eval {
self.version = "1.0.0"
self.copyright = "(c) 2023, by author"
self.creator = "shubhamaher"
self.description = "A widget for SketchUp."
Sketchup.register_extension(self, true)
}
end
end
From files within your extension sibfolder … you can get the folder path using Ruby’s global __dir__()
method.
# encoding: UTF-8
# SketchUp extension loader file: "ShubHam_Widget/loader.rb"
module ShubHam
module Widget
require File.join( __dir__, "widget_lib.so" )
end
end
But be aware that for so
, dll
, dylib
files loaded with Ruby’s require
they must have a proper entry point function defined.
// "widget_lib.cpp"
// C++ functions ...
extern "C" {
// Ruby entry point function always begins with "Init_", ends with file name:
void Init_widget_lib() {
// Define ruby interface here which call C++ functions above ...
}
}
For more information, read the book on extending Ruby with C.