Can't read backslash with Sketchup.read_default !
-
I can't get the backslash reading a path from registry-key in Windows 7 x64!
path = Sketchup.read_default("MyPlugin", "path")
I know I could change the backslash "" with a slash "/" or even 2 backslashes "\" before using write.default but isn't there a way to read a normal Windows path as in "C:\Program Files (x86)\SketchUp\SketchUp 2013\Plugins" from the registry?
In my search for an answer I found on http://ruby-doc.com/docs/ProgrammingRuby/html/ref_c_string.html#String.gsub:
"hello".gsub('.') {|s| s[0].to_s + ' '}
Typing this in the Ruby Console it displays just "hello", not what it should give according to that site:
"104 101 108 108 111 "thanks
-
Bottom line:
Sketchup.read_default
has been bugged for years.
We have complained for years.
They have continually marked it as low priority.
They have not fixed it yet.The method also will not read DWORD values.
It is implemented in a funky way that actually runs what it reads thru
eval()
so as to convert strings like"true"
back intotrue
(an actual instance ofTrueClass
.)Because it evals the path string it sees the backslashes as escape characters.
If you are done waiting for it to be fixed, use the Win32API library to make system calls to read the registry. (Or use Win32OLE, or call a separate Visual Basic script etc.)
-
Thank you!
Any link to learn using Win32API and Win32OLE in Ruby? -
When you do a
write_default
for your "path" just usepath.tr("\\","/")
on it beforehand - then it'll be OK in the PC's registry [or MAC's plist].
When youread_default
it back in, you just usepath.tr("/","\\")
- if you have to.
Ruby and many other functions in Windows are happy enough to use/
- so why do you need to change it at all ?
If you need to reuse the path within perhaps a .cmd, .bat or .vbs context [with DOS-like coding] then it will need a\
, so then you can use.tr("/","\\")
on it before reuse ??
It's always best to use/
as the folder path separators - the paths are then PC and MAC compatible, in Ruby and most other usages... -
But they said he/she knew how to do that... so I assumed they wanted to read a path that perhaps the application wrote into the registry.
Quickie Info on WIN32OLE and Win32API:
http://phrogz.net/ProgrammingRuby/lib_windows.html#microsoftwindowssupportYou can use the Windows Shell object via WIN32OLE:
http://msdn.microsoft.com/en-us/library/aew9yb99(v=vs.84).aspxand call it's RegRead method:
http://msdn.microsoft.com/en-us/library/x05fawxd(v=vs.84).aspxSomewhere there was an example... ?
-
Thank you Dan!
Do you also know what they mean with:
"Note that Win32API is deprecated in Ruby 1.9.2"Does that mean I shouldn't use any Win32API to be compatible from 1.9.2 and up?
Found that on http://en.wikibooks.org/wiki/Ruby_Programming/Standard_Library/Win32API
-
Well it is replaced with Win32API.rb which is a wrapper that uses the
DL
library.
So you can still use it. In later versions evenDL
is deprecated and becomes a wrapper into theFiddle
library.They (the Ruby Core people,) want coders to begin using the newer libs. But not every user installs the full Ruby libraries. It is easier to just use the
Win32API
class, for now.
Advertisement