• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

UI.savepanel question

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 4 Posters 365 Views
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.
  • G Offline
    glro
    last edited by 28 Apr 2012, 12:45

    trying to save the current model, using

    
    model = Sketchup.active_model
    path = UI.savepanel("Save Model to","*.skp")
    #this line retrieves the model path but with "\" instead of "/"
    #so later, the path is not recognised
    #how to change "\" into"/" in the path?
    #?????
    #save
    #nomsauv = "??path with / instead of \??"
    #Sketchup.active_model.save (nomsauv)  
    #Sketchup.file_new
    #Sketchup.open_file (nomsauv)  
    
    

    "" is interpreted as an escape character, and i can't find a way to change it into "/"

    Anybody has a solution?

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 28 Apr 2012, 14:14

      In ruby, always use / as path separator. Under Windows it will translate / to \ .

      If you need to use \ within a string, escape it: "Hello \\ World"

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 28 Apr 2012, 14:49

        The model.save(path) fails when there are \ [or \] as the separators [for some inexplicable reason !] - but Sketchup's UI.savepanel() returns the path with \ on a PC !!!

        To ensure all \ become / I'd use path.tr!("\\","/") before doing the save, so they will all be / .

        TIG

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 28 Apr 2012, 14:58

          @tig said:

          To ensure all \ become / I'd use path.tr!("\\","/") before doing the save, so they will all be / .

          Or File.expand_path( filename )

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • G Offline
            glro
            last edited by 28 Apr 2012, 15:08

            @thomthom said:

            In ruby, always use / as path separator. Under Windows it will translate / to \ .

            If you need to use \ within a string, escape it: "Hello \\ World"

            Thank you for the answer

            The problem is that i don't choose to use "", UI.savepanel does

            I found the line of code that changes "" into "/"; and yes, "within a string, escape it"
            it is: filepath=filepath.tr ("\","/")

            favicon

            (www.sketchucation.com)

            now it works

            
            model = Sketchup.active_model
            filepath = UI.savepanel("Save Model to","*.skp")
            # transform "\" into "/"
            filepath=filepath.tr("\\","/")
            #save the file
            Sketchup.active_model.save (filepath)  
            #open a new file (that is close the one that has just been saved)
            Sketchup.file_new
            #open the file that has just been saved
            Sketchup.open_file (filepath)
            
            
            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 28 Apr 2012, 15:17

              That's what I said; Sketchup returns some PC paths using \ but then needs / in some of its other methods, which is pretty illogical... 😒

              Your...
              filepath=filepath.tr("\\","/")
              can be done with a "change in place" '!', as I showed...
              filepath.tr!("\\","/")
              or as Thomthom says, you get the same results with...
              File.expand_path( filename )
              which also ensures all separators are /...

              All three ways will give the same result.

              TIG

              1 Reply Last reply Reply Quote 0
              • G Offline
                glro
                last edited by 28 Apr 2012, 16:13

                @tig said:

                That's what I said; Sketchup returns some PC paths using \ but then needs / in some of its other methods, which is pretty illogical... 😒

                Your...
                filepath=filepath.tr("\\","/")
                can be done with a "change in place" '!', as I showed...
                filepath.tr!("\\","/")
                or as Thomthom says, you get the same results with...
                File.expand_path( filename )
                which also ensures all separators are /...

                All three ways will give the same result.

                yes, Ruby seems as powerful and confusing as human language...

                thank you for your help

                1 Reply Last reply Reply Quote 0
                • D Offline
                  Dan Rathbun
                  last edited by 28 Apr 2012, 23:59

                  Sketchup.open_file (filepath)

                  Do not put a space between method names and the ( ) of the argument list. It will lead to confusing the Ruby interpreter, especially when there are multiple arguments.

                  I'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    Dan Rathbun
                    last edited by 29 Apr 2012, 00:02

                    FYI .. file_new() will close the active model only on Windows (because it's not an MDI interface.) On Mac.. another document window is opened, and becomes active, but the old one with the old model is still open.

                    This post belongs in the Ruby forum.

                    I'm not here much anymore.

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

                    Advertisement