• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Startup Switches

Scheduled Pinned Locked Moved Developers' Forum
17 Posts 6 Posters 3.9k Views 6 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    alexschreyer Extension Creator
    last edited by 24 Jan 2009, 19:25

    Does anyone know if SketchUp has startup switches (like AutoCAD, for example)? I am thinking of something like:

    sketchup.exe /p "d:/plugins"

    AutoCAD does this nicely. For example, additional support files can be loaded at startup with a shortcut that contains the /s switch. This makes it easier to use the software in a "locked-down" computer lab where you have your own customized extension files on a USB stick.

    Author of "Architectural Design with SketchUp":
    http://sketchupfordesign.com/

    1 Reply Last reply Reply Quote 0
    • C Offline
      Chris Fullmer
      last edited by 25 Jan 2009, 08:54

      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

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 25 Jan 2009, 15:11

        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"
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • W Offline
          watkins
          last edited by 25 Jan 2009, 17:39

          Dear Jim,

          Does that mean that one could load different plugin folders, e.g. plugin_arch, plugin_mech etc?

          Regards,
          Bob

          1 Reply Last reply Reply Quote 0
          • A Offline
            alexschreyer Extension Creator
            last edited by 25 Jan 2009, 19:40

            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

            Author of "Architectural Design with SketchUp":
            http://sketchupfordesign.com/

            1 Reply Last reply Reply Quote 0
            • J Offline
              Jim
              last edited by 25 Jan 2009, 21:35

              @watkins said:

              Dear Jim,

              Does that mean that one could load different plugin folders, e.g. plugin_arch, plugin_mech etc?

              Regards,
              Bob

              In 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.

              Hi

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by 25 Jan 2009, 21:40

                @alexschreyer said:

                Does anyone know a good solution to get a directory path using a selection box?

                Cheers,
                Alex

                Not using the the Ruby API. I don't know off-hand if anyone has ever posted another solution.

                Hi

                1 Reply Last reply Reply Quote 0
                • A Offline
                  alexschreyer Extension Creator
                  last edited by 25 Jan 2009, 22:07

                  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

                  Author of "Architectural Design with SketchUp":
                  http://sketchupfordesign.com/

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    alexschreyer Extension Creator
                    last edited by 26 Jan 2009, 02:11

                    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

                    Author of "Architectural Design with SketchUp":
                    http://sketchupfordesign.com/

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      Jim
                      last edited by 26 Jan 2009, 02:27

                      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"))
                      
                      

                      Hi

                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        alexschreyer Extension Creator
                        last edited by 26 Jan 2009, 02:38

                        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

                        Author of "Architectural Design with SketchUp":
                        http://sketchupfordesign.com/

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          Jim
                          last edited by 26 Jan 2009, 21:07

                          @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")
                          
                          

                          Hi

                          1 Reply Last reply Reply Quote 0
                          • thomthomT Offline
                            thomthom
                            last edited by 3 Jul 2009, 11:24

                            @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 used require_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.

                            Thomas Thomassen — SketchUp Monkey & Coding addict
                            List of my plugins and link to the CookieWare fund

                            1 Reply Last reply Reply Quote 0
                            • J Offline
                              Jim
                              last edited by 3 Jul 2009, 13:33

                              No, it IS the require_all method from sketchup.rb. It was meant as a reference.

                              Hi

                              1 Reply Last reply Reply Quote 0
                              • thomthomT Offline
                                thomthom
                                last edited by 3 Jul 2009, 13:40

                                Ah. -so it loads al ruby resources in the sub-folders as well?

                                Thomas Thomassen — SketchUp Monkey & Coding addict
                                List of my plugins and link to the CookieWare fund

                                1 Reply Last reply Reply Quote 0
                                • C Offline
                                  Chris Fullmer
                                  last edited by 3 Jul 2009, 16:29

                                  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.

                                  Lately you've been tan, suspicious for the winter.
                                  All my Plugins I've written

                                  1 Reply Last reply Reply Quote 0
                                  • TIGT Offline
                                    TIG Moderator
                                    last edited by 3 Jul 2009, 22:20

                                    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...

                                    TIG

                                    1 Reply Last reply Reply Quote 0
                                    • 1 / 1
                                    • First post
                                      Last post
                                    Buy SketchPlus
                                    Buy SUbD
                                    Buy WrapR
                                    Buy eBook
                                    Buy Modelur
                                    Buy Vertex Tools
                                    Buy SketchCuisine
                                    Buy FormFonts

                                    Advertisement