sketchucation logo sketchucation
    • 登入
    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!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update

    Setting file types in the savepanel

    已排程 已置頂 已鎖定 已移動 Developers' Forum
    21 貼文 8 Posters 2.2k 瀏覽 8 Watching
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • T 離線
      tvcasualty
      最後由 編輯

      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 條回覆 最後回覆 回覆 引用 0
      • 1
      • 2
      • 2 / 2
      • 第一個貼文
        最後的貼文
      Buy SketchPlus
      Buy SUbD
      Buy WrapR
      Buy eBook
      Buy Modelur
      Buy Vertex Tools
      Buy SketchCuisine
      Buy FormFonts

      Advertisement