Getting file paths in SU 7
-
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?
-
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.
-
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.
-
puts __FILE__ (eval) nil
SU7 on Windows7.
-
I'm such a numpty! I tested it in the Ruby Console...
Just please ignore everything I've said in this thread.
-
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__))
-
Sketchup 7 uses Ruby 1.8.0 like Sketchup 6 does. Type VERSION to see the version number into the Ruby Console.
azuby
-
@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
-
@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.
Advertisement