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

Setting file types in the savepanel

Scheduled Pinned Locked Moved Developers' Forum
21 Posts 8 Posters 1.8k 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.
  • T Offline
    talig
    last edited by 23 Apr 2009, 21:30

    Hi again everyone,
    I've got a simple one this time πŸ˜„
    I want to set the "save as type" value in the savepanel. To, let's say, *.csv. It's true that I can make the file be whatever I want it to be, but I'm thinking usability here.
    So - does anyone have a clue?
    Thanks,

    • Tali

    p.s. Thanks to you guys I'm drawing near to wrapping up this project I'm working on. πŸ‘

    Avatar: all rights reserved to Bryan Eppihimer

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 24 Apr 2009, 11:51

      You can't specify a file-type but you can give the default file-name + .file-type-suffic

      filepath=UI.savepanel("DialogTitle","DirectoryPath","DefaultFileName.csv")
      

      that way at least the user starts off with a proper file name that they can mangle later...
      You can trap erroneous filepath names later. Let's say that the user inputs "MyFile" without the .csv suffix: use the variable 'filepath' to test it.

      filepath=filepath.tr("\\","/")#in case any PC ruby weirdness...
      filebase=File.basename(filepath,".csv")#name with suffix stripped
      filename=File.basename(filepath)#name with suffx attached
      if filebase != filename #it's NOT a .csv file
        UI.messagebox("Filename must end with '.csv' - it will be added...")# option error report
        filename=filebase+".csv"
        filepath=File.dirname(filepath)+filename
      end#if
      

      Now you can use 'filepath' to save the file etc...
      Alternatively you could pop up the error message and then immediately re-open the 'savepanel' - perhaps using the 'corrected name' as the new file's default-name - in case the user is likely to totally mistype...
      .

      TIG

      1 Reply Last reply Reply Quote 0
      • T Offline
        talig
        last edited by 24 Apr 2009, 18:07

        Thanks TIG,
        I know I can set the default file name.
        But I find it puzzling that the list of file types exists but it's empty and can't be filled. This isn't the case when you're trying to save a model - so it must be possible somehow, and if not - I guess it's the most trivial wishlist item... 😞
        I'll wait to see if someone knows how to do this.

        Avatar: all rights reserved to Bryan Eppihimer

        1 Reply Last reply Reply Quote 0
        • W Offline
          WorCoder
          last edited by 20 Oct 2010, 15:23

          Just getting this thread out of retirement...

          Is there any new solution to this?
          I would love to see this one fixed. (Meaning a possible mask application or anything for the filetype selector in the savepanel.)

          Regards 😎

          1 Reply Last reply Reply Quote 0
          • H Offline
            honoluludesktop
            last edited by 20 Oct 2010, 19:49

            Jim, Thanks. I knew about the .ext bug making _.ext, but didn't know about using it with ""|nil. So, there is no way to force the savepanel to open with .ext in a predetermined folder?

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 20 Oct 2010, 19:52

              Why (""|nil) instead if just nil ?

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

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jim
                last edited by 20 Oct 2010, 19:53

                Apologies - that was just meant as a notation for either "" or nil.

                Hi

                1 Reply Last reply Reply Quote 0
                • T Offline
                  thomthom
                  last edited by 20 Oct 2010, 19:55

                  Ah, gotcha!

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

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    Jim
                    last edited by 20 Oct 2010, 20:04

                    @honoluludesktop said:

                    So, there is no way to force the savepanel to open with *.ext in a predetermined folder?

                    Not that I know.

                    Hi

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      Jim
                      last edited by 21 Oct 2010, 00:04

                      Still can't add filetypes to the "Save as type" dropdown, as far as I know.

                      But you can provide a extension mask as follows:

                      UI.savepanel "Title", nil, "*.rb" (can use empty String or nil for middle param)

                      Note, if you try to provide a directory name (the 2nd parameter,) the file mask gets messed up - it's a bug (IMO.) The file mask asterisk will get translated into an underscore: " _.rb"

                      And this might only work on Windows, I don't know.

                      Also, to work around the bug it may be possible to use Dir.chdir() to set the default directory before calling savepanel. (Update: Looks like this doesn't work. Windows must store the MRU location somewhere.)

                      Hi

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        thomthom
                        last edited by 21 Oct 2010, 08:56

                        It's been reported before - but it doesn't hurt reminding them...
                        http://forums.sketchucation.com/viewtopic.php?f=11&t=29023

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

                        1 Reply Last reply Reply Quote 0
                        • W Offline
                          WorCoder
                          last edited by 21 Oct 2010, 09:01

                          Thanks for the effort, guys.
                          Sadly this doesn't really help.

                          Seems to me as more inconvenient to have to move to the desired folder every time.

                          What bugs me the most is, that one can't click save and then immediately start typing the filename, in the way that the whole line (including ".xxx")is highlighted.

                          Since there might be some not really intelligent people handling this, I would love a way for them to immediately start typing, but still have the right extension visible as well.
                          Do I have to file a bug-report to get this in or is there nothing one can do to try and get functionality of the filetype selector!?

                          1 Reply Last reply Reply Quote 0
                          • T Offline
                            TIG Moderator
                            last edited by 21 Oct 2010, 09:25

                            If the users are so stupid why even give them the chance of saving the file in a weird folder or giving it a stupid name ?
                            Why not always locate and name the file 'with the model'.
                            First use a trap (puts "Save SKP!";return nil if model.path=="" in case your SKP is not saved.
                            You get the folder from folder=File.dirname(model.path)
                            You could then 'set' the file-name based on the model, so file=model.title+".xxx" or whatever file type suffix you want.
                            You could use the Scene name in the name too...
                            scene=model.pages.selected_page.name.gsub(/[^A-Za-z0-9_-]/,"_")
                            [The gsub is to avoid making a file name with 'illegal' characters like /:"etc]
                            Then file=model.title+"_"+scene+".xxx"
                            OR you could use a file name based on the 'date/time' which will always be different...
                            time=sprintf("%.1d\n",(Time.now.to_f*100))
                            Then file=model.title+"_"+time+".xxx"
                            Set the path=File.join(folder,file).tr("\\","/")
                            [The tr is only to tidy up if you are to display it later - e.g. in a confirming dialog - as you might get a mix of / and \ on a PC]
                            Now use the path to export, or save as a data file etc...
                            Alternatively you could let the user set the file name with a simple inputbox
                            results=inputbox(["File Name: "],[model.title],"Type in XXX File Name [WITHOUT a '.xxx' suffix]") return nil if not results file=(File.basename(results[0]).gsub(/[^A-Za-z0-9_-]/,"_"))+".xxx"
                            which traps 'stupid' input or file suffix...

                            TIG

                            1 Reply Last reply Reply Quote 0
                            • W Offline
                              WorCoder
                              last edited by 21 Oct 2010, 10:33

                              Thanks for those tips! I really appreciate this.

                              I see your point. Since there are pro and dumb users, the features I would love to include are:

                              • selecting your own name for the file
                              • selecting your wished folder to store into
                              • keep "uneducated" users from messing up the filetype
                              • keep a clean interface for ease of use and esthetic reasons

                              And somehow I'm also on the point that talig mentioned

                              @talig said:

                              ...I find it puzzling that the list of file types exists but it's empty and can't be filled.

                              Mainly because I think this is just a basic functionality and I don't see the point in this option not being provided.
                              β˜€

                              1 Reply Last reply Reply Quote 0
                              • W Offline
                                WorCoder
                                last edited by 21 Oct 2010, 10:51

                                P.S.: I did send in a report, so maybe there might be a fix in the future...

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  thomthom
                                  last edited by 21 Oct 2010, 11:02

                                  @worcoder said:

                                  • keep "uneducated" users from messing up the filetype

                                  Can't you just correct the filename you are returned? If there is not file extension, automatically append it before saving? Since Windows since XP hide the file extension on known files many users are completely unaware of file extensions anyway.

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

                                  1 Reply Last reply Reply Quote 0
                                  • W Offline
                                    WorCoder
                                    last edited by 16 Nov 2010, 15:09

                                    @thomthom said:

                                    many users are completely unaware of file extensions anyway.

                                    Sorry for the late reply, was on holiday...
                                    Sure I can correct the file extension, but I'd still love to have the nice looking "clean" solution with a working file type selector. πŸ˜‰

                                    We'll see what the future brings.

                                    1 Reply Last reply Reply Quote 0
                                    • Dan RathbunD Offline
                                      Dan Rathbun
                                      last edited by 17 Nov 2010, 03:33

                                      @thomthom said:

                                      Since Windows since XP hide the file extension on known files many users are completely unaware of file extensions anyway.

                                      Not a given.

                                      On all our machines (or any machine I work on,) I turn file extension display back ON.

                                      I'm not here much anymore.

                                      1 Reply Last reply Reply Quote 0
                                      • T Offline
                                        thomthom
                                        last edited by 17 Nov 2010, 07:16

                                        @dan rathbun said:

                                        @thomthom said:

                                        Since Windows since XP hide the file extension on known files many users are completely unaware of file extensions anyway.

                                        Not a given.

                                        On all our machines (or any machine I work on,) I turn file extension display back ON.

                                        Yes - but by default XP hides it.

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

                                        1 Reply Last reply Reply Quote 0
                                        • Dan RathbunD Offline
                                          Dan Rathbun
                                          last edited by 17 Nov 2010, 08:45

                                          @thomthom said:

                                          Yes - but by default XP hides it.

                                          Which is one of the dumbest things Microsoft does.

                                          I'm not here much anymore.

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

                                          Advertisement