Setting the save path for files ???
-
hi,
here is a small one :retrieve file path works:
model = Sketchup.active_model @local_user_path = model.path puts @local_user_path endbut how can write back the path, when it was changed by save-operations from my ruby, so that
autobackup writes its files to the original file directory and not to the plugin folder ??no "set_path" function in the model class found....
thanx stan
-
` @old_path = model.path
Sketchup.send_action("saveDocument:")make changes here
model.save( @new_path )
Sketchup.open_file( @old_path )`
Note that on the Mac, there will now be 2 document windows open.
-
hi dan,
yes, this is for saving sketchup models from the ruby, right?but skp seems to use the last use directory for saving ( in my case MY save function for my ruby parameters) of further files, like autobackup. they all appear now in the ruby directory.
so can i define somewhere the system variable for the save directory, whithout saving a model file myself ?means, restoring the value of model path from 'old path' by setting a value only?
stan
-
You need to learn the standard Ruby classes File and Dir.
Current Working System directory:
Dir.getwdNEVER trust that it is pointing where you wish, because any script can change it.
BE NICE .. so SAVE and RESTORE it if you change it, when your done.prevdir = Dir.getwd Dir.chdir( @new_path ) # ### save files to new dir with only filespecs # ### Restore previous working directory; Dir.chdir( prevdir )It is initially set to the User's HOME directory (%USERPROFILE% on Windows.)
On MAC:ENV["HOME"]
On Win:ENV["USERPROFILE"]Under Ruby "~/" will only expand to the User's root dir, IF
ENV["HOME"]is defined.
so, on Windows...
ENV["HOME"]=ENV["USERPROFILE"] unless ENV["HOME"]
Other info:
Current models full pathname:
model.pathCurrent models directory:
File.dirname( model.path )Current model's filespec:
File.basename( model.path )Current model's filename:
model.titleCurrent model's file extension:
File.extname( model.path )Joining a new path with a old filespec:
File.join( @new_path, File.basename( model.path ) )
-
hi dan,
that's exactly, what i ment.
i want to restore the user file path after my ruby finished it's job.
perfect!thank you very much, also for the other system variables, very useful for future development.
stan
Advertisement