sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    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.
    • W Offline
      watkins
      last edited by

      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
      • alexschreyerA Offline
        alexschreyer Extension Creator
        last edited by

        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

          @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

            @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
            • alexschreyerA Offline
              alexschreyer Extension Creator
              last edited by

              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
              • alexschreyerA Offline
                alexschreyer Extension Creator
                last edited by

                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

                  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
                  • alexschreyerA Offline
                    alexschreyer Extension Creator
                    last edited by

                    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

                      @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

                        @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

                          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

                            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
                            • Chris FullmerC Offline
                              Chris Fullmer
                              last edited by

                              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

                                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