BrainVoyager Support

documentation overview

  • Increase font size
  • Default font size
  • Decrease font size

Scripts for BrainVoyager QX 2.1 and higher

Example scripts for BrainVoyager QX 2.1 and higher

Contents of this page (latest update: 22-11-11)

Example processing scripts for BrainVoyager 

Example non-GUI scripts: 

 

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()

Introduction

In BrainVoyager QX 2.1, the JavaScript language is used. This is almost similar to the scripting language that was used before, until BrainVoyager QX 2.0, called Qt Script for Applications (QSA). The scripts now have a *.js extension instead of *.qs for a script of *.qsa for a script project. The scripting guide (*.pdf) for BrainVoyager QX 2.1 can be downloaded from the Automation and Development page. Information can also be found on the GUI Scripts page in the BrainVoyager User's Guide. Also online, there is a JavaScript language reference from w3schools (external link).


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. And here is a proper createprotocol script.

 

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
~~~~
 
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.