Message 1 of 3
Code snippet: GetMultOpenFilenames()

Not applicable
09-26-2007
04:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
A post in the old forums asked about multiple select in the built-in getOpenFilename() dialog. I whipped up a little function using a .NET object that will do it. I just wrote it now, so it may still be a little rough.
Its parameters are close enough to those of getOpenFilename() that it does not need much of its own documentation. It returns an array of strings or 'undefined' if the dialog is canceled.
I take no responsibility for errors or the trouble they may cause; it seems to work fine, but the function was the result of about ten minutes of work and has not undergone much testing.
A general question: for short code snippets like this, are attachments preferred to in-post text?
Its parameters are close enough to those of getOpenFilename() that it does not need much of its own documentation. It returns an array of strings or 'undefined' if the dialog is canceled.
I take no responsibility for errors or the trouble they may cause; it seems to work fine, but the function was the result of about ten minutes of work and has not undergone much testing.
fn GetMultiOpenFilenames caption:"Open" filename:"" types:"All Files (*.*)|*.*" default:1 =
(
local dlg = DotNetObject "System.Windows.Forms.OpenFileDialog"
dlg.multiSelect = true
dlg.title = caption
local p = getFilenamePath filename
if doesFileExist p then
dlg.initialDirectory = p
-- MAXScript getOpenFilename uses trailing |;
-- OpenFileDialog filter does not.
if types == "|" then
dlg.filter = (substring types 1 (types.count - 1))
else
dlg.filter = types
dlg.filterIndex = default
local result = dlg.ShowDialog()
if (result.Equals result.OK) then
dlg.filenames
else
undefined
)
A general question: for short code snippets like this, are attachments preferred to in-post text?