Brain Innovation

support portal


BrainVoyager Available Tools Available Plugins Visual Scripting Editor III

Visual Scripting Editor III

First scripts

If you are not familiar with scripting/coding, we recommend you start with some exercices from Blockly. The maze and pond tutor are the most appropriate to complete before starting with BrainVoyager scripts.

The scripts proposed here are taken from the BrainVoyager "Getting starte guide for scripting" and show you the basic blocks. The number in front of the script refer to the manual section.

Note that the resulting scripts will not always be exaclty the same than the scripts printed in the getting started guide. This is due to the fact that each block does not always relate to a single command. Sometimes, a block may call two or more commands. This simplify the number of block but may slightly complexify the script. Loop and condition blocks may also change sligthly from the standard use. They are written to be safe first and accomodate many different situations.

Chapter 2 - Script to open an FMR project

Script 2.1

For this script to run properly, you may have to create the directory pointed by the function "BrainVoyagerQX.PathToSampleData" and have downloaded the sample data. Alternatively, write the full path to one of your vmr dataset in a single text block.

Run the script via the “Run” button of the BrainVoyager scripting editor or directly from the “Scripts” menu in BrainVoyager. The VMR project will now be opened by BrainVoyager.

Note that we did not use the output option of the "Open Document" block and that for this block this is just fine.

Chapter 3 - Using filenames

In this script, we first need to create a variable. Press "Variables" in the toolbox, then create variable, you will be prompted for the name of the new variable. For this script type "fmrfilename" and press "OK".

Create a new variable

New blocks are created by the visual editor which allow you to assign a "value" to the variable, change the variable or use the variable.

After the creation of a new variable

In the chapter 3 script, we first assign a "value" to the variable using the "set" block then use the variable with the latest block.

Script 3

Running the script in BrainVoyager will result in printing the filename to the BrainVoyager Log tab.

A variable is a container which contain may change during your program. In the chapter 3 script, you assign the file name to the variable but, alternatively, you may use the block browse file block to load a file during the execution of the script by BrainVoyager.

Chapter 4 - Following the processing in BrainVoyager

In this script, we do not follow exactly the script presented in the manual. We prefer to let the user decide the image to play with while running the script, and we use a variable to hold the value of the target volume used for motion correction.

Script 4a

Running this script in BrainVoyager will result in the comment to be printed in the log, the fmr project to be open in BrainVoyager and corrected for motion correction.

The last variable, success, is a boolean variable which will be true if the motion correction is executed correctly, false otherwise.

In the browse file block, you can adapt your file search by modifying the "filter" parameter. To look for all files, you may enter "*.*"

Using variable instead of directly the value, you can easily modify the value of the variable, only one line to change, and do not need to check all your script for other occurence of the variable/value.

Now, instead of writing to the log, we will write to a file.

Script 4b

You first need to open the file for writing. A new variable is created by the block which contains the path to the file. This variable will be used by the script to indicate in which file it has to write. In such a way, you may open multiple files at once. Every "Write" block will write a single line to the file. When you finish writting to the file, you have to close the file.

Chapter 5 - Preprocessing several files

In chapter 5, the script use arrays and loops for applying slice scan time correction to several files. To do this, the previous script are extended with a list and a loop. This approach allows to apply the same procedure to several files. Therefore we store the variables in a list, and process them one by one with a loop.

Script 5

To create a list, first you have to create a variable. Then use one of the create list blocks. The variable may now contains multiple values.

The loop will assign one element of the list to the variable "i" which is automatically created when you use the loop block. You may rename that variable for clarity using the drop-down menu. "i" will then contain a file name. The value of "i" will change with each passage in the loop till all files have been processed.

Chapter 6 - Creating a function within the script

Sometimes, you have to repeat a couple of instructions several times in a script, or you need them in multiple scripts. In that case, you better write a function containing all these instructions and that you insert once in your script and call it when needed. Chapter 6 describe a function used to open a file containing a list of file to process. The first line contains the number of files and, then, one file per line.


You first need to create a function. Here, select the block with "return" as it allows to return a value after executing the function.

Select a function block

Replace do_something by a function name. Then, click on the ? and write a comment explaining your function. This comment will also be saved in the script file. Click again on the ? to hide the comment.

Add a comment to the function

Our function will have to read a file. We want to give it the filename of the file to read as an input. Click on the "gear" to open a new menu allowing you to add inputs. Select one input block on the left and insert it in the right block. You can change the x by a more appropriate name. Close the submenu by pressing the "gear" again. A function will use variable as input. This allow a more universal use of the function. While calling the function, you can either use a variable or directly a value. You do not need to use the same variable name when calling the function. The name given as input is for internal use only.

Select the number of input

To write a function, insert your blocks in your function block. When the function is finished, connect a value or a variable to the return

A function block

A short note on the use of list. If you use this function in Python, the list block, where the list is filled, will not work. The list usage is often tricky and prone to memory problem. In the present exemple, we increase the list by adding a new element to the a new position. This way work fine for Javascript but Python prefer the following alternative:

A function block

In both Python and JavaScript, i should always be the element right after the last element in the list

The function can be called from anywhere in your program.

A function block

You are here: HomeBrainVoyagerAvailable ToolsAvailable Plugins ≫ Visual Scripting Editor III