SF - Adding Scripts

Please read the introduction to “Simulation Flow” to become familiar with its mode of operation. There, you will also find a description of how to add new scripts.

By clicking on “Add Script”, the appropriate tab in the window's right panel becomes active and a new entry becomes visible in the pipeline, similar to the ones in the image.

The script's 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, right-click on the name and choose “Rename” to make it editable. You can now enter a new description. With this pipeline you always have an overview of which scripts are used 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 of putting each function into an individual script and reusing it somewhere else (although this process might require some changes to the script, esp. in terms of variables). 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”.

To work with the selected script, click on its name and use the editor right to the simulation tree. RealFlow creates a new tab for each script. 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 via 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 unchecking 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 bear 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 plug-in 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 right panel 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. You can still use the “Master” section, but you should write and organize scripts with the new tools. Next to “Master” there are two more tabs containing empty editors. By default they are 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.

Writing Python Scripts

The creation of scripts requires knowledge of a programming language. We have chosen Python, because it can be considered a quasi-standard and is implemented in most 3D programs. Python is very easy to learn, provides countless extensions (so-called modules) and supports modern approaches like object-oriented programming.

The core of RealFlow's Python interface is the Software Development Kit – the SDK. The SDK contains all available commands and can be seen as a reference or a dictionary where you can look up a particular function. There you learn how to use a function, which arguments it requires and what it will finally return as a result. The SDK is completely integrated into RealFlow's internal help system. We have also added a context-sensitive help: when you start to write a script, RealFlow's Python editor recognizes your input and directly shows the possible commands in a drop-down list. So, if you are not 100% sure how a certain command is named or used, you do not have to refer to the “Help Viewer's” Python reference, but simply choose the desired entry from the context menu.

To get you started with Python, we have created a sophisticated introduction to Python scripting with RealFlow. There you will find all relevant information about things like data types, operators, conditions and many real-life examples. The Python scripting guide can be found here:

RealFlow's Python Scripting Guide