Brain Innovation

support portal

16-11-22: Please note that the JavaScript function LoadVOIFile() does not seem to work in BrainVoyager 22.2 and 22.4; this has been reported. The Python function load_vois() could be used temporarily instead.

Introduction

The following JavaScript-scripts (*.js) can be used from BrainVoyager QX 2.1 or 2.2; the example (non-GUI) scripts are now updated to BrainVoyager 20+, including the use of the new Getting Started Guide data (Sept 2019). They are an addition to the scripts that are available in the folder /(My) Documents/BVExtensions/Scripts/ after installation of BrainVoyager. The scripting guide (*.pdf) for BrainVoyager can be downloaded from the Scripting Reference page. Also online, there is a JavaScript language reference from w3schools (external link).

Contents of this page 

BrainVoyager 23, added 13-02-24 (zipped): createMultipleFuncNIfTIBIDS.js, gui_tutorial_6.qml, CreateVMRAndIIHCAndAutoTALAndMNI_BV23.js, CreateVTCfiles_BV23.js, ExperimentalDesign_BV23.js, LinkPRTSaveVTC_BV23.js, CreateMDM_MultiGLMs_BV23.js

Example processing scripts for BrainVoyager 20+ (19-09-19) including CreateDocuments_BV21_NewGSGdata.js, CreateVMRAndAutoTAL_BV21.js, etc.

Example non-GUI scripts: 

Get the path from a file 
Creating a class for custom objects 
Preprocess multiple runs
Read a text file with filenames
Matrix functions
List files and directories of a directory
Create directory
Remove spaces in filename

Example GUI scripts:
     Print to Log when clicking button
     Demonstration of use of most important graphical components (widgets) 
     Conditional enabling of widgets
     Returning and passing parameters to functions
     Using tabs and shortcut names for widgets using findChild()


Example processing scripts for BrainVoyager QX

Example creation of BrainVoyager projects (FMR/DMR/VMR), preprocessing and creation of VTC/VDW files scripts: ExampleScriptsBVQX21_030210.zip
Please note that the FMR preprocessing script has been updated (03-02-'10), which contained an obsolete function; also the cubic spline interpolation parameter for slice scan time correction has been added in the comments.

Example non-GUI scripts

getPath.jsScript to extract the path from a filename using JavaScript string functions "lastIndexOf()" and "substring()".

classes.js: Sometimes it can be useful to create custom-made objects, for example when creating an FMR project many times. The parameters for the project creation can then be concisely stored in one object, so that one doesn't need to pass a lot of parameters to a function, but only one instance of a class.

preprocess_fmrs.js: Simple script to show how to use a loop and an array in preprocessing multiple runs, using slice scan time correction as example. 

read_projectinfo.js: A script to read a text file with filenames/directorynames and some number (of runs, for example) into a two-dimensional array so that the filenames do not need to be added to a (preprocessing) script, but are external to the script. The expected text file structure is:

[number of pairs]
[some filename 1]
[some number 1]
[some filename 2]
[some number 2]
...
[some filename n]
[some number n]
For example, for 2 subjects, the first with 3 runs and the second with 2 runs:
~~~
2
/Users/me/Data/subject1/
3
/Users/me/Data/subject2/
2
~~~~

matrix_functions.js: A simple script for calculating with 4x4 matrices. Just change the matrix in the script and then run in BrainVoyager to calculate the result. Available functions in the script: getIdentityMatrix(), getEmptyMatrix(), multiply4x4Matrices(mat1, mat2), getdeterminant(a), getinverse(mat), printMatrixToLog(matrix, name). This script can for example be used to check whether the orientation of an image was reversed during import from NIfTI (see example use of getdeterminant() in script).

List_directories_and_files.js: Print directory names and file names of a certain directory. Edit the directory name in the script before running it.
 
createDirectory.js: Script to create a subdirectory in directory selected by file browser.
 
remove_spaces_in_filename.js     Script to remove spaces in a filename. Usage: place in /Documents/BVQXExtensions/Scripts/, start BrainVoyager > Scripts > "remove spaces in filename"; a filedialog will ask for the name of the file to be changed. Please note: the script has not been tested for situations where there is a space in the path name.
Example GUI scripts
In graphical user interface (GUI) scripts, user input is collected from the signals emitted from the components on the dialog (*.ui), for example from buttons, radiobuttons, dropdownboxes etc (also called 'widgets'). In the script (*.js) these signals can be caught and processed. For example, if the PushButton to start preprocessing has been clicked, invoke in the script a preprocessing function. A dialog can stay active for a long time, so a button could be clicked several times, if this is desirable. For capturing the emitted signals, the following properties can be used: 
          PushButton: clicked 
          RadioButton: toggled
          CheckBox: stateChanged
          LineEdit: editingFinished
          TextEdit: textChanged (emit signal after each character)
The use of these signals has been illustrated in the extPrintDlg.js/ui script below.
For obtaining the information in the widgets, the following properties of the respective widgets can be used:
Label: text
RadioButton: checked
CheckBox: checked
LineEdit: text
TextEdit: plainText
ComboBox: currentIndex, currentText (QX 2.2 and higher)
SpinBox: value
DoubleSpinBox: value
TimeEdit: time
DateEdit: date
For example: 'BrainVoyagerQX.PrintToLog("Information from line edit: " + FMRnameLineEdit.text);'
and 'BrainVoyagerQX.PrintToLog("Number of projects: " + FMRnrProjectsSpinBox.value);'
printDlg.js/ui
Contents
: This script bundle consists of printDlg.js (the script to load in BrainVoyager) and printDlg.ui (the user interface of the script), place both in /Documents/BVQXExtensions/Scripts/ folder.
Functionality: The script will print "Script > Dialog’s Print to Log button clicked" to the BrainVoyager QX log tab if the button with label and name 'btnPrint' is clicked.
Usage: In the BrainVoyager menu, select 'Scripts' > 'Edit and Run Scripts...' and click 'Load...' to load this script, then 'Run'.

extPrintDlg.js/ui
Contents
: This script bundle consists of extPrintDlg.js (the script to load in BrainVoyager) and extPrintDlg.ui (the user interface of the script), place both in the /Documents/BVQXExtensions/Scripts/ folder.
FunctionalityThe script will print input from the widgets (graphical components on the dialog) to the BrainVoyager QX log tab if the button with label 'print input' and name 'btnPrint' is clicked. Some widgets will print as well after their value has been changed.
// Some widgets will emit signals, and also print their input to the BrainVoyager QX loSome widgets will emit signals, and also print their input to the BrainVoyager QX log tab.
Usage: In the BrainVoyager menu, select 'Scripts' > 'Edit and Run Scripts...' and click 'Load...' to load this script, then 'Run'. The dialog should appear, its values can be changed and printed to the BrainVoyager QX Log tab when the 'print input' button is clicked.
 

conditionalEnabling.js/ui 
Contents: This script bundle consists of conditionalEnabling.js (the script to load in BrainVoyager) and conditionalEnabling.ui (the user interface of the script), place both in the /Documents/BVQXExtensions/Scripts/ folder.
Functionality: When clicking the button, the 'enabled' status of the checkbox will change and vice versa.
// Some widgets will emit signals, and also print their input to the BrainVoyager QX loSome widgets will emit signals, and also print their input to the BrainVoyager QX log tab.
Usage: In the BrainVoyager menu, select 'Scripts' > 'Edit and Run Scripts...' and click 'Load...' to load this script, then 'Run'. The dialog should appear, the checkbox and button status can be changed until the dialog is closed. 

Returning and passing parameters:     non-GUI version (*.js)    GUI version (*.js/*.ui)
Purpose: show how to pass and return parameters between functions when creating BrainVoyager QX 2.1 scripts without and with a graphical user interface (GUI).
Dialog of returning and passing parameters script

tabbedDlg.js/ui
Purpose: Addressing widgets using the findChild() function. In case many graphical components are used, like checkboxes on tabbed widgets, their names can become complicated and it can be hard to find how to address them. To solve this, the findChild() function has been provided. The current example listens to signals emitted from a radiobutton and checkbox located on a tabbed widget; the signals are connected to functions, which print something to the BrainVoyager QX Log tab.
using_tabbedwidget_with_findchild_function2 
Please note: in BrainVoyager QX 2.2, use 'BrainVoyagerQX.FindChild()' instead.
You are here: HomeBrainVoyagerAvailable ToolsAvailable Scripts ≫ Scripts for BrainVoyager (JavaScript)