Hi Everyone,
I’m trying to explore some automation using ruby API. I create a ruby file (.rb) which is located in plugins folder (C:\Users\tks\AppData\Roaming\SketchUp\SketchUp 2023\SketchUp\Plugins) and then the plugin can be used from extension tab in SketchUp UI.
I don’t know how I can debug my code step by step while using the SketchUp application. Either I’ve to check the portions of the code either in ruby console or sometimes I have to do below process in order to get the changes loaded for the plugin =>
close the SketchUp application >> 2. save the changes into .rb file >> 3. then open the SketchUp application again.
Ie, a proper extension registrar script and a extension subfolder of the same name with the code files in the folder ?
Sometimes this is easier because it clears out memory. But you can use the console to reload specific code files using the global load() method. (This method requires the full path and a file type as the argument.)
You can also create menu items that do the reload and later remove them when you publish the extension.
Ie, something like this in your extension code within your extension’s subfolder.
# Within your extension subfolder ONLY.
# Do not put this code in a file in the "Plugins" folder !
module TKS
module SomePlugin
if !defined?(@gui_loaded)
# This assumes you have created a SketchupExtension object in a registrar
# file in the "Plugins" folder, referenced by a local constant EXTENSION.
UI.menu("Developer").add_item("Reload Code Files: #{EXTENSION.name}") {
prev_dir = Dir.pwd
Dir.chdir(__dir__) do
Dir.glob("*.rb").each { |rb_file| load(rb_file) }
rescue => error
puts error.inspect
puts error.backtrace
Dir.chdir(prev_dir)
end
}
@gui_loaded = true
end
end
end
This can be very technically complicated and there are other topics about this: