Back slashes in read_default
-
Wow,
I was really surprised that this code failed so badly
(responses from the ruby console are indented)splant_file = "c;\\tmp\\test1.ArPlant" c;\tmp\test1.ArPlant Sketchup.write_default("RpTreeMaker","test",splant_file) "c;\tmp\test1.ArPlant" Sketchup.read_default("RpTreeMaker","test","") c; mp est1.ArPlant
The backslashes followed by T got converted to tabs after being processed by write_default and then read_default.
-
Hi Al,
I just did some experiments and found that the / works just fine as a file path separator on both windows (and I assume macs.) It might save you some headaches.
-
Thanks,
The file name though came from an OpenFile dialog (which returns back slashes), and would be passed to one later (which requires back slashes).
So I had to convert the code to look like this:
slast = Sketchup.read_default("RpTreeMaker", "slast_plant_file", "")
slast = slast.tr!("/", "\")splant_file = file_save_dialog( "ArPlant file", "ArPlant Files (*.ArPlant)\0", "ArPlant", slast )
return if !splant_filewe cannot write \ to SkecthUp defaults
splant_file.tr!("\","/")
Sketchup.write_default("RpTreeMaker", "slast_plant_file", splant_file) -
I think that's a common idiom when dealing with file paths in plugins, although I use
"path\\to\\file.ext".gsub!(/\\/, '/')
I did try openpanel and savepanel, and both appear to work using the / character, so you'd only need to translate on the initial path retrieval.
You can write \ to the the sketchup defaults, but you need to escape the 's
file = "c;\\\\tmp\\\\test1.ArPlant"] Sketchup.write_defaults "Lib", "Key", file
-
Thanks for helping look into this Jim.
GetSaveFile probably accepts the / as well. (I didn't test it).
I have always been a little disappointed in UI.openpanel.
Using Win32API.so (which requires that you install a second file with your plugin and only works with Windows Apps), lets me specify patterns for acceptable extensions, and also to specify a default extension to be appended if the user doesn't enter one.
And the GetOpenFile version lets me require that the file exist before the use can hit OK.
Small things. But it is too bad that SketchUp can't find the time to update some of their routines. (This could easily be done with either new routines, or optional parameters, to make them a little more useful.)
However, the main point of the original post is that it would be nice if you could pass write_default() a string and have it save it and return it, without having to "reverse engineer" which characters don't work.
Advertisement