UI.savepanel question
-
trying to save the current model, using
model = Sketchup.active_model path = UI.savepanel("Save Model to","*.skp") #this line retrieves the model path but with "\" instead of "/" #so later, the path is not recognised #how to change "\" into"/" in the path? #????? #save #nomsauv = "??path with / instead of \??" #Sketchup.active_model.save (nomsauv) #Sketchup.file_new #Sketchup.open_file (nomsauv)
"" is interpreted as an escape character, and i can't find a way to change it into "/"
Anybody has a solution?
-
In ruby, always use / as path separator. Under Windows it will translate / to \ .
If you need to use \ within a string, escape it:
"Hello \\ World"
-
The
model.save(path)
fails when there are \ [or \] as the separators [for some inexplicable reason !] - but Sketchup'sUI.savepanel()
returns the path with \ on a PC !!!To ensure all \ become / I'd use
path.tr!("\\","/")
before doing the save, so they will all be / . -
@tig said:
To ensure all \ become / I'd use
path.tr!("\\","/")
before doing the save, so they will all be / .Or
File.expand_path( filename )
-
@thomthom said:
In ruby, always use / as path separator. Under Windows it will translate / to \ .
If you need to use \ within a string, escape it:
"Hello \\ World"
Thank you for the answer
The problem is that i don't choose to use "", UI.savepanel does
I found the line of code that changes "" into "/"; and yes, "within a string, escape it"
it is: filepath=filepath.tr("\","/")now it works
model = Sketchup.active_model filepath = UI.savepanel("Save Model to","*.skp") # transform "\" into "/" filepath=filepath.tr("\\","/") #save the file Sketchup.active_model.save (filepath) #open a new file (that is close the one that has just been saved) Sketchup.file_new #open the file that has just been saved Sketchup.open_file (filepath)
-
That's what I said; Sketchup returns some PC paths using \ but then needs / in some of its other methods, which is pretty illogical...
Your...
filepath=filepath.tr("\\","/")
can be done with a "change in place" '!', as I showed...
filepath.tr!("\\","/")
or as Thomthom says, you get the same results with...
File.expand_path( filename )
which also ensures all separators are /...All three ways will give the same result.
-
@tig said:
That's what I said; Sketchup returns some PC paths using \ but then needs / in some of its other methods, which is pretty illogical...
Your...
filepath=filepath.tr("\\","/")
can be done with a "change in place" '!', as I showed...
filepath.tr!("\\","/")
or as Thomthom says, you get the same results with...
File.expand_path( filename )
which also ensures all separators are /...All three ways will give the same result.
yes, Ruby seems as powerful and confusing as human language...
thank you for your help
-
Sketchup.open_file (filepath)
Do not put a space between method names and the
( )
of the argument list. It will lead to confusing the Ruby interpreter, especially when there are multiple arguments. -
FYI ..
file_new()
will close the active model only on Windows (because it's not an MDI interface.) On Mac.. another document window is opened, and becomes active, but the old one with the old model is still open.This post belongs in the Ruby forum.
Advertisement