In SP/core.rb I load my other files and create everything my extension needs:
Sketchup.require("SP/foo")
...
Now with Sketchup.require('file') it will load the correct file, but in the initializer of SketchupExtension I need to register a specific file. Do I need to make the distinction myself? Is the registration itself in the proper place or should this go into another file?
Is there supposed to be another way now that SU2016 encrypts some file itself?
SketchupExtension itself doesn’t require this - but Extension Warehouse do. So does the new extension signing. It’s a structure required such that SketchUp can treat the files as a bundle.
Btw, beware of __FILE__ as under Windows there is a bug in Ruby that will label the incorrect encoding to the string returned. This easily cause errors with file paths with unicode characters. (Some users will have unicode usernames and hence in their user folder where SketchUp’s Plugins folder is located.)
Quick question: why do you have the …/ prefix there? That makes it point to the parent directory.
File.expand_path('../Gemfile', __FILE__)
is a somewhat ugly Ruby idiom for getting the absolute path to a file when you know the path relative to the current file. Another way of writing it is this:
SketchupExtension will internally call Sketchup.require on the file you provide it. So you’d have something like this:
Cool, didn’t know this existed. Thanks
By the way, the correct naming convention would be for the support folder to have the same name as the registration file:
Ok, renamed it correctly.
Btw, beware of FILE as under Windows there is a bug in Ruby that will label the incorrect encoding to the string returned. This easily cause errors with file paths with unicode characters. (Some users will have unicode usernames and hence in their user folder where SketchUp’s Plugins folder is located.)
plugin = SketchupExtension.new(File.basename(__FILE__, ".*"), File,join(File.basename(__FILE__, ".*"), "core.rb")
# i.e. "SP/core.rb" ### you could add the whole path too...
Sketchup.register_extension(plugin, true) # 'SP'
In SP/core.rb you then “load” the other file[s] to create everything the extension needs:
Sketchup.require(File.join(File.dirname, "foo"))
# or better "foo.rb" to 'freeze' the loader and avoid hijacking with hacker's added .rbs earlier loading even after 'signing' in v2016.