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

    Getting file paths in SU 7

    Scheduled Pinned Locked Moved Developers' Forum
    9 Posts 6 Posters 472 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.
    • Al HartA Offline
      Al Hart
      last edited by

      Did the result of:

      mydir = File.dirname(__FILE__)
      

      change for SU 7 (and/or Vista)?

      If so, how are people getting the location of a .rb file?

      Al Hart

      http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
      IRender nXt from Render Plus

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

        I was wondering that myself... I thought I'd used that before, but when I wanted to get the plugin directory recently it didn't seem to work.

        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

          It works for me in SU7 & XP - what is the value of FILE?

          puts __FILE__
          C;/Program Files/Google/Google SketchUp 7/Plugins/tmp/file.rb
          
          

          I know it barfs when the file is encrypted.

          Hi

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

            
            puts __FILE__
            (eval)
            nil
            
            

            SU7 on Windows7.

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

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

              I'm such a numpty! I tested it in the Ruby Console... 😳

              Just please ignore everything I've said in this thread.

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

              1 Reply Last reply Reply Quote 0
              • A Offline
                avariant
                last edited by

                Since that is a ruby constant, or whatever, not an SU specific thing, I wouldn't have expected it to change. I don't think the version of ruby is different between XP and Vista (1.8.6 right?).

                Here are a couple alternatives I found around

                
                File.expand_path(__FILE__+'/..') 
                File.dirname(File.expand_path(__FILE__)) 
                
                
                1 Reply Last reply Reply Quote 0
                • A Offline
                  azuby
                  last edited by

                  Sketchup 7 uses Ruby 1.8.0 like Sketchup 6 does. Type VERSION to see the version number into the Ruby Console.

                  azuby

                  *error initus :: Blocks | CurrentDate | d/Code | extensionmanager | FFlipper | HideEdges | MeasuredArea | ModelHistory | PluginsHelp | PronButton | SAWSO | SCP | SU²CATT

                  Bad English? PM me, correct me. :smile:**

                  1 Reply Last reply Reply Quote 0
                  • Al HartA Offline
                    Al Hart
                    last edited by

                    @unknownuser said:

                    I know it barfs when the file is encrypted.

                    Thanks to all for helping me look into this. (The .rps barf comment provided the clue)

                    I found the problem. We are using a ruby '<<' construction to turn the whole source of a .rb file into a string, and then execute it with TOPLEVEL_BINDING. This makes the error messages and trace messages report the proper file and line numbers with .rbs files.

                    However, we were passing the eval() function the basename of the file rather than the full path name.

                    For other programmers using .rbs files, who want error paths reported properly, here is the code to place around the contents of your .rb file.

                    
                    printf("***** Loading; %s\n",File.basename(__FILE__))
                    start_line = 3 # set to current line
                    sexec_string = <<-'END_FILE'
                    
                    [... contents of ruby source file ...]
                    
                    END_FILE
                    #load the file with proper binding, name, etc.
                    begin
                    	eval(sexec_string, TOPLEVEL_BINDING, __FILE__, start_line+2) # add 2 to start_line
                    rescue Exception => $emess
                    	printf("ERROR loading; %s\n\t%s\n\tin; %s\n", __FILE__, $emess.message,$emess.backtrace[0])
                    end
                    

                    Al Hart

                    http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
                    IRender nXt from Render Plus

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      RickW
                      last edited by

                      @jim said:

                      I know it barfs when the file is encrypted.

                      We've asked Google to fix this, but no dice yet.
                      Ditto on Ruby access to Dimension objects.

                      RickW
                      [www.smustard.com](http://www.smustard.com)

                      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