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

    File Path with backslashes

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 4 Posters 323 Views 4 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.
    • W Offline
      whodah
      last edited by

      Hello,

      I'm new to this. I'm using a Windows system and am tweaking the nifty SVG plugin:
      http://flightsofideas.net/?p=572

      It has a line in the code of:

      
      @svgFilename = Sketchup.active_model.get_attribute "foi_svg_export", "svgFilename", "flightofideas.svg"
      
      

      When one invokes the plugin, a pop-up box comes up with that path for the "Output File":
      http://www.flickr.com/photos/27621953@N02/3768086037/

      When first invoked, that path is simply "flightofideas.svg" until you specify (or navigate) a path. Subsequent changes remember that path. I'd like to automate that a bit and default that field to the drawing's working path to get you started. So far, from this post, I am at:

      
      @svgFilename = Sketchup.active_model.get_attribute "foi_svg_export", "svgFilename", File.dirname(mymodel.path)+mymodel.title+".svg"
      
      

      But instead of "C:/users/user/desktop/Untitled.svg" I get "C:usersuserdesktopUntitled.svg" (note the lack of slashes)

      Also, I have a feeling that I'll need to add a slash on my own after the path and before the model. But I can't seem to get that working either.

      Any ideas/help?

      Thanks!

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

        Try
        File.join(File.dirname(mymodel.path), mymodel.title+".svg").tr("\\","/")
        OR even the clunkier
        (File.dirname(mymodel.path)+"/"+mymodel.title+".svg").tr("\\","/")
        It you don't tell your code what to do it won't do it πŸ˜’

        BUT note how the path part will automatically contain separator slashes - which on a PC these are \ NOT /.
        So it could be that the \ slashes in the path are getting things confused in the dialog code, so try the 'tr' conversion of \ to / - the / will work fine for both PC or MAC, and in js, webdialogs etc...
        EDIT: Typo corrected to .tr("\\","/") TIG.

        TIG

        1 Reply Last reply Reply Quote 0
        • A Offline
          Aerilius
          last edited by

          Maybe it would be logical to convert input file paths as early as possible to the Ruby notation, namely
          mymodelpath = File.expand_path(mymodel.path) File.join(File.dirname(mymodelpath), mymodel.title+".svg")
          This way you never have both delimiters at the same time, and by using Ruby's method %(#000000)[File.expand_path] your script is truely platform-agnostic (which is better than hardcoding delimiters for 1, 2, etc. platforms).

          1 Reply Last reply Reply Quote 0
          • W Offline
            whodah
            last edited by

            Hi,

            I realize that I forgot to mention that I am defining mymodel as:

            
            mymodel = Sketchup.active_model
            
            

            TIG: thanks! I hear ya on the \ vs. / thing for windows. But / is what the SVG script shows on the screen when one chooses a path, even on this windows environment. I tried both:

            
            File.join(File.dirname(mymodel.path), mymodel.title+".svg").tr("\"","/")
            
            

            and:

            
            (File.dirname(mymodel.path)+"/"+mymodel.title+".svg").tr("\"","/")
            
            

            which both resulted in:
            C:usersuserdesktop/Untitled.svg

            Aerilius: that did the trick, thank you very much!
            πŸ˜„

            Your code results in:
            C:/users/user/desktop/Untitled.svg

            (and it works with the SVG plugin!)

            Final code that works for those googling down the road:

            
            mymodel = Sketchup.active_model
            mymodelpath = File.expand_path(mymodel.path)
            @svgFilename = Sketchup.active_model.get_attribute "foi_svg_export", "svgFilename", File.join(File.dirname(mymodelpath), mymodel.title+".svg")
            
            
            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              TIG's example:
              .tr("\"","/")
              means replace all double quotes with a slash.

              It probably should be:
              .tr("\\","/")

              I'm not here much anymore.

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

                @dan rathbun said:

                TIG's example:
                .tr("\"","/")
                means replace all double quotes with a slash.
                It probably should be:
                **.tr("\\","/")**
                Dan thanks for spotting my typo. I've corrected the original... By coincidence I was doing some changes between double and single quotes and it got stuck in my muscle memory !

                TIG

                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