sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🫛 Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Setting file types in the savepanel

    Scheduled Pinned Locked Moved Developers' Forum
    21 Posts 8 Posters 2.0k Views 8 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.
    • T Offline
      tvcasualty
      last edited by

      Sorry to drudge up old news, but this is an embarrassingly old issue, be nice to have a filter option in the API by now.
      Here was my solution because I didn't like the fact that it could possibly overwrite a file accidentally using TIGs approach (untitled != untitled.txt for example). Anyhow it can be a burden to hit save twice, but I'd rather do that 100x then accidentally save over something important.

      Where:

      
      EXT = "txt"
      default_dir = "c;\\temp\\"
      default_file = "untitled"
      
      

      The following while loop:

      
      name_valid = false 
      while name_valid == false 
       path_to_save_to = UI.savepanel("Save Code File", default_dir, default_file)
       #path_to_save_to = path_to_save_to.tr("\\","/") # This maybe required.
       fileext = File.extname(path_to_save_to) # filename with prefix stripped
       filebase = File.basename(path_to_save_to, ".#{EXT}")
       #puts fileext.inspect
       if fileext == "" || fileext == nil
        default_file = filebase + ".#{EXT}"
        UI.messagebox "Oops! Including the file extension '#{EXT}'\nThis is an embarrassing workaround...\nPlease hit save again."
        #puts default_file.inspect
       else
        filename = filebase + ".#{EXT}"
        path_to_save_to = File.dirname(path_to_save_to) + "\\" + filename
        name_valid = true
       end
      end
      
      
      1 Reply Last reply Reply Quote 0
      • 1
      • 2
      • 2 / 2
      • First post
        Last post
      Buy SketchPlus
      Buy SUbD
      Buy WrapR
      Buy eBook
      Buy Modelur
      Buy Vertex Tools
      Buy SketchCuisine
      Buy FormFonts

      Advertisement