File dialogs can be used let the user select a file or indicate a file name to save a file.
In the simplest version, just use
function Get_filename() {
var filename = FileDialog.getOpenFileName();
BrainVoyagerQX.PrintToLog(filename);
}
and the filename is represented in the variable 'filename'.
Return values
When the user clicks 'Cancel', the filename will contain a string "undefined" (in BrainVoyager QX 1.9 an object undefined).
To test whether the user did click 'Cancel' or not, a simple test can be used. In this function, the script will open
function Get_filename_with_filter_safe_version() {
var vmr;
var filename = FileDialog.getOpenFileName("*.vmr");
BrainVoyagerQX.PrintToLog("VMR name: " + filename);
if (filename != "undefined") {
vmr = BrainVoyagerQX.OpenDocument(filename);
} else {
BrainVoyagerQX.PrintToLog("User pressed cancel: VMR will not be opened.");
}
}
The VMR variable referring to the VMR project is declared on beforehand, because the script won't have access to the vmr variable when it is declared in the 'if {}' block.
In the function above, a filter is used. When the file dialog will appear when running the script, only files with the *.vmr extension will be highlighted. Other file types cannot be selected and will be, dependent of the platform, grayed out (Apple) or not visible (Windows).
The order
for the arguments of the function FileDialog.getOpenFileNames(<dir>)
has changed.
To select from a directory using a predefined path, use
1. var <varname> = FileDialog.getOpenFileNames(<filter>,
<dirname>, <title>);
like in the example:
var projectPath
= FileDialog.getExistingDirectory();
firstFilesArray[i] = FileDialog.getOpenFileNames("*.dcm", projectPath, "Please
choose the first file of project
" + (i+1));
or:
1. Get and set the directory first
2. Then get the filename via getOpenFileName(<filter>, <title>);
like in the example:
var projectPath
= FileDialog.getExistingDirectory();
BrainVoyagerQX.SetCurrentDirectory(projectPath);
firstFilesArray[i] = FileDialog.getOpenFileName("*.dcm", "Please
choose the first file of project
" + (i+1));