💡 LightUp 7.1 | SketchUp's only real-time renderer that uses object-based rendering
Download Trial
Setting file types in the savepanel
-
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
Advertisement