Go to: Synopsis. Return value. Flags. MEL examples.

Synopsis

fileDialog2 [-buttonBoxOrientation int] [-cancelCaption string] [-caption string] [-dialogStyle int] [-fileFilter string] [-fileMode int] [-fileTypeChanged script] [-hideNameEdit] [-okCaption string] [-optionsUICancel script] [-optionsUICommit script] [-optionsUICommit2 script] [-optionsUICreate script] [-optionsUIInit script] [-optionsUITitle string] [-returnFilter boolean] [-selectFileFilter string] [-selectionChanged script] [-setProjectBtnEnabled boolean] [-startingDirectory string]

fileDialog2 is undoable, NOT queryable, and NOT editable.

This command provides a dialog that allows users to select files or directories.

Return value

stringarray

Flags

buttonBoxOrientation, cancelCaption, caption, dialogStyle, fileFilter, fileMode, fileTypeChanged, hideNameEdit, okCaption, optionsUICancel, optionsUICommit, optionsUICommit2, optionsUICreate, optionsUIInit, optionsUITitle, returnFilter, selectFileFilter, selectionChanged, setProjectBtnEnabled, startingDirectory
Long name (short name) Argument types Properties
-buttonBoxOrientation(-bbo) int create
  • 1 Vertical button box layout. Cancel button is below the accept button.
  • 2 Horizontal button box layout. Cancel button is to the right of the accept button.
-cancelCaption(-cc) string create
If the dialogStyle flag is set to 2 then this provides a caption for the Cancel button within the dialog.
-caption(-cap) string create
Provide a title for the dialog.
-dialogStyle(-ds) int create
  • 1 On Windows or Mac OS X will use a native style file dialog.
  • 2 Use a custom file dialog with a style that is consistent across platforms.
-fileFilter(-ff) string create
Provide a list of file type filters to the dialog. Multiple filters should be separated by double semi-colons. See the examples section.
-fileMode(-fm) int create
Indicate what the dialog is to return.
  • 0 Any file, whether it exists or not.
  • 1 A single existing file.
  • 2 The name of a directory. Both directories and files are displayed in the dialog.
  • 3 The name of a directory. Only directories are displayed in the dialog.
  • 4 The names of one or more existing files.
-fileTypeChanged(-ftc) script create
MEL only. The string is interpreted as a MEL callback, to be called when the user-selected file type changes. The callback is of the form:

global proc MyCustomFileTypeChanged(string $parent, string $newType)

The parent argument is the parent layout into which controls have been added using the optionsUICreate flag. The newType argument is the new file type.

-hideNameEdit(-hne) create
Hide name editing input field.
-okCaption(-okc) string create
If the dialogStyle flag is set to 2 then this provides a caption for the OK, or Accept, button within the dialog.
-optionsUICancel(-oca) script create
MEL only. The string is interpreted as a MEL callback, to be called when the dialog is cancelled (with Cancel button or close button to close window). The callback is of the form:

global proc MyCustomOptionsUICancel()

-optionsUICommit(-ocm) script create
MEL only. The string is interpreted as a MEL callback, to be called when the dialog is successfully dismissed. It will not be called if the user cancels the dialog, or closes the window using window title bar controls or other window system means. The callback is of the form:

global proc MyCustomOptionsUICommit(string $parent)

The parent argument is the parent layout into which controls have been added using the optionsUICreate flag.

-optionsUICommit2(-oc2) script create
MEL only. As optionsUICommit, the given string is interpreted as a MEL callback, to be called when the dialog is successfully dismissed. The difference is that this callback takes one additional argument which is the file name selected by the user before the dialog validation. It will not be called if the user cancels the dialog, or closes the window using window title bar controls or other window system means. The callback is of the form:

global proc MyCustomOptionsUICommit(string $parent, string $selectedFile)

The parent argument is the parent layout into which controls have been added using the optionsUICreate flag.

-optionsUICreate(-ocr) script create
MEL only. The string is interpreted as a MEL callback, to be called on creation of the file dialog. The callback is of the form:

global proc MyCustomOptionsUISetup(string $parent)

The parent argument is the parent layout into which controls can be added. This parent is the right-hand pane of the file dialog.

-optionsUIInit(-oin) script create
MEL only. The string is interpreted as a MEL callback, to be called just after file dialog creation, to initialize controls. The callback is of the form:

global proc MyCustomOptionsUIInitValues(string $parent, string $filterType)

The parent argument is the parent layout into which controls have been added using the optionsUICreate flag. The filterType argument is the initial file filter.

-optionsUITitle(-oti)
2023
string create
MEL only. If optionsUICreate is set, user can set a custom title to their option window using this flag. If no title is desired, an empty string i.e. "" can be used.
-returnFilter(-rf) boolean create
If true, the selected filter will be returned as the last item in the string array along with the selected files.
-selectFileFilter(-sff) string create
Specify the initial file filter to select. Specify just the begining text and not the full wildcard spec.
-selectionChanged(-sc) script create
MEL only. The string is interpreted as a MEL callback, to be called when the user changes the file selection in the file dialog. The callback is of the form:

global proc MyCustomSelectionChanged(string $parent, string $selection)

The parent argument is the parent layout into which controls have been added using the optionsUICreate flag. The selection argument is the full path to the newly-selected file.

-setProjectBtnEnabled(-spe) boolean create
Define whether the project button should be enabled
-startingDirectory(-dir) string create
Provide the starting directory for the dialog.

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can be used more than once in a command.

MEL examples

// Single file filter with no description.
string $basicFilter = "*.mb";
string $result[] = `fileDialog2 -fileFilter $basicFilter -dialogStyle 2`;

// Single filter with a description.
string $singleFilter = "All Files (*.*)";
string $result[] = `fileDialog2 -fileFilter $singleFilter -dialogStyle 2`;

// Multiple filters separated by double semi-colons. The first filter has multiple file types.
string $multipleFilters = "Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb);;All Files (*.*)";
string $result[] = `fileDialog2 -fileFilter $multipleFilters -selectFileFilter "Maya Binary" -dialogStyle 2`;

//
// An example of how to add UI to the Maya file dialog.
//

global proc MyCustomOptionsUISetup(string $parent)
{
setParent $parent;
$parent = `scrollLayout -childResizable true`;

// generate some UI which will show up in the options tab of the Maya file dialog
columnLayout -adj true;
iconTextRadioCollection itRadCollection;
iconTextRadioButton -st "iconAndTextVertical" -i1 "sphere.png" -l "sphere" SphereIconButton;
iconTextRadioButton -st "iconAndTextVertical" -i1 "cone.png" -l "cone" ConeIconButton;
iconTextRadioButton -st "iconAndTextVertical" -i1 "cube.png" -l "cube" -select CubeIconButton;
}

global proc MyCustomOptionsUIInitValues(string $parent, string $filterType)
{
setParent $parent;
if (`optionVar -exists MyCustomUIOptVar`)
{
string $selected = `optionVar -q MyCustomUIOptVar`;
iconTextRadioCollection -edit -select $selected itRadCollection;
}
}

global proc MyCustomOptionsUICommit(string $parent)
{
setParent $parent;
optionVar -sv MyCustomUIOptVar `iconTextRadioCollection -q -select itRadCollection`;
}

global proc MyCustomSelectionChanged(string $parent, string $selection)
{
setParent $parent;
print ("$selection: " + $selection + "\n");
}

global proc MyCustomFileTypeChanged(string $parent, string $newType)
{
setParent $parent;
print ("$newType: " + $newType + "\n");
}

fileDialog2 -fileFilter "Maya Binary (*.mb);;Maya ASCII (*.ma);;All Files (*.*)"
-optionsUICreate "MyCustomOptionsUISetup"
-optionsUIInit "MyCustomOptionsUIInitValues"
-optionsUICommit "MyCustomOptionsUICommit"
-fileTypeChanged "MyCustomFileTypeChanged"
-selectionChanged "MyCustomSelectionChanged";