Code snippet: GetMultOpenFilenames()

Code snippet: GetMultOpenFilenames()

Anonymous
Not applicable
601 Views
2 Replies
Message 1 of 3

Code snippet: GetMultOpenFilenames()

Anonymous
Not applicable
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.

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?
0 Likes
602 Views
2 Replies
Replies (2)
Message 2 of 3

MartinBeh
Advisor
Advisor
nice, thank you! I really should start learning .Net...
Martin B   EESignature
→ please 'Like' posts that are helpful; if a post answers your question please click the "Accept Solution" button.
0 Likes
Message 3 of 3

Anonymous
Not applicable

A general question: for short code snippets like this, are attachments preferred to in-post text?


For short examples like this, inline is much better - it is easy to read immediately, no downloads required, it is easy to quote in an answer or quickly improve the code and repost etc.

If the code is longer than one page, it should go into an attachment or a link to an online resource.
0 Likes