sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Can't read backslash with Sketchup.read_default !

    Scheduled Pinned Locked Moved Developers' Forum
    7 Posts 3 Posters 461 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • onidarbeO Offline
      onidarbe
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        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 into true (an actual instance of TrueClass.)

        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.)

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • onidarbeO Offline
          onidarbe
          last edited by

          Thank you!
          Any link to learn using Win32API and Win32OLE in Ruby?

          1 Reply Last reply Reply Quote 0
          • TIGT Online
            TIG Moderator
            last edited by

            When you do a write_default for your "path" just use path.tr("\\","/") on it beforehand - then it'll be OK in the PC's registry [or MAC's plist].
            When you read_default it back in, you just use path.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...

            TIG

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              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#microsoftwindowssupport

              You can use the Windows Shell object via WIN32OLE:
              http://msdn.microsoft.com/en-us/library/aew9yb99(v=vs.84).aspx

              and call it's RegRead method:
              http://msdn.microsoft.com/en-us/library/x05fawxd(v=vs.84).aspx

              Somewhere there was an example... ?

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • onidarbeO Offline
                onidarbe
                last edited by

                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

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  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 even DL is deprecated and becomes a wrapper into the Fiddle 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.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Buy SketchPlus
                  Buy SUbD
                  Buy WrapR
                  Buy eBook
                  Buy Modelur
                  Buy Vertex Tools
                  Buy SketchCuisine
                  Buy FormFonts

                  Advertisement