YES. We do this all the time. * CORRECTED in next post.
Your PNG files should have a .png
file extension.
Each of your .rb
files should open your submodule for editing (using Ruby module
blocks.)
Ie …
Your extension’s registrar file In the "Plugins"
folder …
Must be same name as the extension subfolder but with a .rb file extension !
# encoding: UTF-8
# "Plugins/Agent47_BoxMaker.rb"
#
module Agent47
module BoxMaker
EXTENSION ||= SketchupExtension.new(
"BoxMaker", "Agent47_BoxMaker/makebox_loader"
).instance_eval do
# self is the instance object within this block:
self.name= "Agent47's Nifty BoxMaker"
self.description= "Allows the creation of various nifty boxes."
self.version= '1.0.0'
self.creator= "Agent47"
self.copyright= "©2020 by author, All Rights Reserved."
# Return the new object to get assigned to the constant EXTENSION
self
end
Sketchup.register_extension(EXTENSION)
end # close extension submodule
end # close author namespace module
* Changed the SketchupExtension
constructor call’s path
argument to omit the .rb
file extension (as the documentation advises,) so that the loader file can be scrambled or RBE encrypted.
In your extension "Agent47_BoxMaker"
subfolder …
# encoding: UTF-8
# "Plugins/Agent47_BoxMaker/makebox_loader.rb"
#
module Agent47
module BoxMaker
['makebox1','makebox2','makebox_menu'].each do |rb_file|
Sketchup.require( File.join(__dir__, rb_file) )
end
end # close extension submodule
end # close author namespace module
* NOTE: The global __dir__
method returns the full path to where the current evaluating file is located on disk. The File::join
method concatenates parts of pathnames using the File::SEPARATOR
character.
# encoding: UTF-8
# "Plugins/Agent47_BoxMaker/makebox1.rb"
#
module Agent47
module BoxMaker
def make_box_1
# box making code
end
end # close extension submodule
end # close author namespace module
# encoding: UTF-8
# "Plugins/Agent47_BoxMaker/makebox2.rb"
module Agent47
module BoxMaker
def make_box_2
# box making code
end
end # close extension submodule
end # close author namespace module
# encoding: UTF-8
# "Plugins/Agent47_BoxMaker/makebox_menu.rb"
#
module Agent47
module BoxMaker
extend self
if !@loaded # Run only on startup
@loaded = true
# Define Commands, Menu Items and Toolbars here
CMD ||= {}
CMD[:one]= UI::Command.new("Make Box Type 1") { makebox1() }
CMD[:two]= UI::Command.new("Make Box Type 2") { makebox2() }
submenu = UI.menu("Plugins").add_submenu("Agent47")
submenu.add_item(CMD[:one])
submenu.add_item(CMD[:two])
end # Run only on startup block
end # close extension submodule
end # close author namespace module
So, an author can split their extension code up into as many files as they wish to help with code maintenance.