Startup Switches
-
I don't that you can do that, though someone might know more about it.
But you can load ruby scripts directly from the ruby console inside of SU. Type:
load "z;\sketchup\plugins\ScriptName.rb"
And put the correct drive letter for you usb stick and of course the right path and correct plugin name. That works and I use it often.
Or, I haven't tested it, but you could probably even write your own ruby script that loaded all your plugins. So it might be:
load "z;\sketchup\plugins\ScriptName1.rb" load "z;\sketchup\plugins\ScriptName2.rb" load "z;\sketchup\plugins\ScriptName3.rb" load "z;\sketchup\plugins\ScriptName4.rb" load "z;\sketchup\plugins\ScriptName5.rb"
And then from side of SU you could just run your loader script so it would load all your plugins in one shot. I've not tested that script and I'm not a ruby programmer, so don't shoot me if it doesn't work or requires some tweaks. But I think something like that should work. BTW, I'd like to know if it works or not. Thanks,
Chris
-
That's the right idea, Chris. There is a method defined in sketchup.rb called 'require_all' that takes a directory as an argument, and then require's all the .rb files in that directory.
So once SketchUp is running, you should be able to open the Ruby Console and type:
require_all "d;/plugins"
-
Dear Jim,
Does that mean that one could load different plugin folders, e.g. plugin_arch, plugin_mech etc?
Regards,
Bob -
Thanks for your great suggestions. I like both solutions. The require_all one will be a good solution for the computer lab application that I have in mind.
I figured it might be a good idea to wrap that behavior into a plugin. So here's my first attempt (plugin_loader.rb):
require 'sketchup.rb' def load_plugin_file filename = UI.openpanel "Select a SketchUp Plugin File (With RB Extension)", "", "" load filename end def load_plugin_folder # How can we select a folder easily with Ruby??? # require_all foldername end filename = "plugin_loader.rb" if !file_loaded?(filename) # get the SketchUp plugins menu plugins_menu = UI.menu("Plugins") my_menu = plugins_menu.add_item("Load plugin... (file)") { load_plugin_file } my_menu = plugins_menu.add_item("Load plugins... (folder)") { load_plugin_folder } # Let Ruby know we have loaded this file file_loaded(filename) end
Does anyone know a good solution to get a directory path using a selection box?
Cheers,
Alex -
@watkins said:
Dear Jim,
Does that mean that one could load different plugin folders, e.g. plugin_arch, plugin_mech etc?
Regards,
BobIn theory, but it depends on how the script is written. There may be some plugins that make assumptions about where they are installed and where their support files are located, and thus will not work when moved outside the Plugins folder.
-
@alexschreyer said:
Does anyone know a good solution to get a directory path using a selection box?
Cheers,
AlexNot using the the Ruby API. I don't know off-hand if anyone has ever posted another solution.
-
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