sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Trouble loading scripts outside Plugins directory

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 389 Views 4 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.
    • M Offline
      mgianzero
      last edited by

      I'm trying to learn Ruby and stay a bit organized. So I wanted to place my personal ruby scripts under "Documents/Sketchup/Marc_Scripts" on my Mac. I tried following the Google Ruby API website and so I created a script called "myrubyscripts.rb" under the Sketchup Plugins directory. In it I put:

      home = File.expand_path "-"
      myrubyscripts = File.join home, "MyRubyScripts"
      require_all("Documents/Sketchup/Marc_Scripts")

      But it doesn't work. What am I doing wrong?

      Marc

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        Hi Marc,

        I think you need to use the full path to your plugins:

        
        require 'sketchup'
        require_all('/Users/YourUserName/Documents/SketchUp/Marc_Scripts')
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          @mgianzero said:

          home = File.expand_path "-"
          myrubyscripts = File.join home, "MyRubyScripts"
          require_all("Documents/Sketchup/Marc_Scripts")

          You are not using your variable myrubyscripts for anything. Looks like you are passing only part of the path.
          Use some puts to investigate the data you pass around when you experience unexpected problems. That way you can verify that the data you think you pass is what you actually pass.

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

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @mgianzero said:

            I tried following the Google Ruby API website and so .... But it doesn't work. What am I doing wrong?
            The example assumes your script dir is a subdir of 'Plugins'.
            It does not explain the "tricks" of having a dir elsewhere.

            @mgianzero said:

            So I wanted to place my personal ruby scripts under "Documents/Sketchup/Marc_Scripts" on my Mac. I created a script ... In it I put:

            home = File.expand_path "-"
            (1) the HOME shortcut is a tilde char "~" not a dash.
            (2) You dont need a "home" var because it's already defined in the Environment Variable Hash on the Mac. To access it from Ruby use: ENV['HOME']
            So... the following:

            @mgianzero said:

            myrubyscripts = File.join home, "MyRubyScripts" require_all('Documents/Sketchup/Marc_Scripts')
            ..becomes:
            require 'sketchup' myscripts = File.join(ENV['HOME'],'Documents/Sketchup/My_Scripts')
            require_all( myscripts )

            This is the equivalent of what Jim showed with a literal argument.

            The drawback is you wind up with all the script entries in the $" array being long absolute paths. You could save memory space by stealing and modifying the code block within sketchup.rb::require_all, like so:

            
            begin
              # require('sketchup') ## not needed
              myscripts = ENV['HOME']+'/Documents/Sketchup/My_Scripts'
              $;.push( myscripts ) # add to $LOAD_PATH array
              old_wd = Dir.getwd   # save old working dir
              wd = Dir.chdir( myscripts )
              rbfiles = Dir["*.{rb,rbs}"]
              rbfiles.each {|f|
                if f.split('.').last=='rbs'
                  Sketchup.require( f )
                else
                  require( f )
                end
              }
              Dir.chdir(old_wd) # restore old working dir
            end
            
            

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • M Offline
              mgianzero
              last edited by

              Thanks Dan. I think I'll stick with your simplified solution. Works perfectly!

              Now I can keep my plugins separate from the ones I downloaded from other folks.

              Marc

              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