Simulation Flow Scripts

Scripts can handle different tasks and therefore it is necessary to distinguish a few types. Within RealFlow there are three fundamental types:

  1. Batch scripts
  2. Simulation Flow scripts (aka "events scripts")
  3. Custom node scripts

Each of these types has its own editor window. Even if the windows appear different, they have some important similarities. The visual appearance of the scripting windows is controlled by RealFlow’s preferences, where you can adjust things like font type, syntax colours and folders for storing your programs:

Menu bar > File > Preferences > Script (Windows/Linux)

Menu bar > RealFlow > Preferences > Script (OS X)

Syntax highlighting is another important similarity. Whenever RealFlow detects an instruction or known function in your code, it will be coloured. For all scripting windows, RealFlow provides auto completion. This function helps you to complete a statement with the help of a drop-down menu. It appears when parts of a command are recognized and allows you to choose the desired function.

How to Work with the Simulation Flow Tree?

"Simulation Flow" scripts are always connected to a certain project and stored directly with the scene. They can also be saved as individual files and used for other scenes, but in this case they normally have to be adapted. Events are start and end of a simulation or the beginning of a new time step or frame. Scripts are not limited to one of these events. You can write one part that is only executed at the beginning of the simulation and another one that is applied at each simulation step. These types of “split” scripts are often used to initialize a scene or reset values to defaults, and then perform the actual calculation. 

Menu Bar > Layout > Simulation Flow (Ctrl + F2)

 

The first impression shows a split window. The upper part consists of a tree with three higher-ranking entries:

  1. SimulationPre
  2. Frames
  3. SimulationPost

 

 

“Frames” also carries a little “+” or “-” symbol, indicating that this menu can be expanded or collapsed. The branches of the tree are where you can place your own scripts and directly determine when they will be executed. This tree also represents the internal hierarchy:

A. Simulation > B. Frame > C. Step

Simulation events can carry more than one script. It is possible to add one or more scripts for any event that wears a “Pre” or “Post” suffix. The scripts can be appended by choosing the desired event, e.g. "FramesPre", and right-clicking on it. This action opens a context menu with some entries:

 

 

The first menu in the previous image shows the entries without any attached scripts. The second menu also provides a “Remove” function to delete existing scripts from the tree. By clicking on “Add Script” a new editor window is opened and a new entry becomes visible in the pipeline, similar to the ones in the image on the right.

This name is generated automatically and has a successive ID. Of course, it is possible to change this name to a more project-related label. To do so, close the script editor and double click on the name to make it editable. You can now enter a new description. With this pipeline you always have an overview of which scripts are called at a certain event, but that is not the only advantage: You also no longer need very long and extended scripts, because you have the possibility to put each function into an individual script and reuse it somewhere else. Another strong feature is that it is possible to shift script nodes from one event to another. In situations where it is better to start a calculation after a frame has been finished instead of executing it before, you do not need to copy and paste the scripts. You can simply drag the desired script from “FramePre” to “FramePost” and that is it.

To work with the selected script, either double-click on its name or use the editor below. If you want to delete a script, simply click on “Remove”. Please note that a removed script is not stored, unless you have saved it manually before from the script editor. The script editor itself provides a few basic operations under its menu bar.

To run a simulation without a certain script, it is not necessary to delete it. You can just set it to inactive by unticking the appropriate checkbox.

 

RealFlow's tree for events scripts.

 

Once a script has been stored, it can be used again and again. You can also load a script from another source, e.g. RealFlow’s scripting homepage. With “Add Script From File” a script can be imported. Please keep in mind that external scripts usually have to be adjusted to your needs and nodes. A completely new function is the “Add From Plugin” option. With this method it is possible to choose a custom plugin from the "Command Plugins" manager, where you will find all available plugins. The “Expand All” button simply expands all branches from the scripts pipeline marked with the “+” symbol.

The lower part of the events window shows a “Master” tab together with a menu bar, consisting of four entries. These menus are exactly the same as described under “Common Settings”. This section was added for compatibility reasons, because Python scripts from RealFlow 4 used a different structure with predefined functions. Next to “Master” there is another tab containing an empty editor. By default it is named “None Selected”, but when you choose a script from the tree, you can edit it there, instead of constantly opening and closing separate windows.

 

You can still use the “Master” section, but we recommend to write and organize scripts with the new tools.


The execution of a "Simulation Flow" script can be very time consuming, depending on the complexity of your script and the performed calculations. You will also see a significant drop in simulation speed with scripts, mainly with events scripts (Python is single-threaded).