sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Back slashes in read_default

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 2 Posters 376 Views 2 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.
    • Al HartA Offline
      Al Hart
      last edited by

      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.

      Al Hart

      http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
      IRender nXt from Render Plus

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        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.

        Hi

        1 Reply Last reply Reply Quote 0
        • Al HartA Offline
          Al Hart
          last edited by

          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_file

          we cannot write \ to SkecthUp defaults

          splant_file.tr!("\","/")
          Sketchup.write_default("RpTreeMaker", "slast_plant_file", splant_file)

          Al Hart

          http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
          IRender nXt from Render Plus

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            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
            
            

            Hi

            1 Reply Last reply Reply Quote 0
            • Al HartA Offline
              Al Hart
              last edited by

              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.

              Al Hart

              http:wiki.renderplus.comimageseefRender_plus_colored30x30%29.PNG
              IRender nXt from Render Plus

              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