Startup Switches
-
Thanks, Jim. I was thinking about a (dirty) way: Let user select file in folder and then parse the directory path. Apparently that needs some conversion of backslashes into forward ones inbetween to get the Ruby functions to do it but it may work. Another option is a UI library, of course.
Cheers,
Alex -
This is turning more into a Ruby topic...
I tried the plugin loader with a few plugins and as Jim assumed some load and some don't. I don't know too much about Ruby, but one that puzzled me because it didn't work was the oniondome.rb. It requires only the 'parametric.rb' and 'bezier.rb' scripts, which in turn require only 'sketchup.rb'. All are in the same folder (/plugins/inactive/).
Are there any SU Ruby functions that assume a file to be in the Plugins folder although no absolute path is given in a plugin?
Cheers,
Alex -
Well, here is the code for require_all:
def require_all(dirname) begin rbfiles = Dir[File.join(dirname, "*.rb")] $;.push dirname rbfiles.each {|f| require f} rescue puts "could not load files from #{dirname}" end end
You will see a special variable $: which is an array and contains the load paths used by the load and require methods. Here is the result of entering $: in the Ruby Console on my PC:
$; ["C;/Program Files/Google/Google SketchUp 7/Plugins", "C;/Program Files/Google/Google SketchUp 7/Tools", "C;/Program Files/Google/Google SketchUp 7/Plugins/Podium"]
The require_all method adds the sub-directory to the load path before trying to require the .rb file, so any support files can technically be stored in the sub-folder also.
I will check out oniondome.rb to see if there is anything unusual there... it works for me. You do need to use the full path such as;
require_all(File.join(Sketchup.find_support_file("plugins"),"inactive"))
-
Thanks, Jim! That's when Ruby is starting to turn cryptic on me...
Seems somewhat straight-forward, though. All we need now is the directory selection dialog.I wanted to preset the file selection dialog to the plugin folder, seems like I can do that with $:[0]. Sweet!
Cheers,
Alex -
@alexschreyer said:
I wanted to preset the file selection dialog to the plugin folder, seems like I can do that with $:[0]. Sweet!
That may work, but I am unsure if the order will be identical on every system SketchUp is installed on. I would just use
plugins_folder = Sketchup.find_support_file("Plugins")
-
@jim said:
Well, here is the code for require_all:
> def require_all(dirname) > begin > rbfiles = Dir[File.join(dirname, "*.rb")] > $;.push dirname > rbfiles.each {|f| require f} > rescue > puts "could not load files from #{dirname}" > end > end >
You will see a special variable $: which is an array and contains the load paths used by the load and require methods. Here is the result of entering $: in the Ruby Console on my PC:
> $; > ["C;/Program Files/Google/Google SketchUp 7/Plugins", "C;/Program Files/Google/Google SketchUp 7/Tools", "C;/Program Files/Google/Google SketchUp 7/Plugins/Podium"] >
The require_all method adds the sub-directory to the load path before trying to require the .rb file, so any support files can technically be stored in the sub-folder also.
I will check out oniondome.rb to see if there is anything unusual there... it works for me. You do need to use the full path such as;
> require_all(File.join(Sketchup.find_support_file("plugins"),"inactive")) >
Does this override the existing built-in
require_all
method?
I usedrequire_all
in CityGen to load the modules, but I don't want it loading the sub-folder. If this overrides the existing method it could potentially cause problems. -
No, it IS the require_all method from sketchup.rb. It was meant as a reference.
-
Ah. -so it loads al ruby resources in the sub-folders as well?
-
I don't think that it loads the sub folders at all. It looks like it just loads the .rb files from the specified psth.
-
I think that the built-in
require_all
method doesn't load anything other than *.rb files in the given folder. My snippet in the other thread made it do sub-folders too...
Advertisement