Adding Python Scripts

It is a common situation: you are browsing forums and video platforms and then you are seeing a neat script that does exactly what you have been looking for. The question is now how to transfer this script to RealFlow?

You can find a long list with batch and simulation scripts in the  "Python Code Examples" section, as well as a short introduction to Python.

Script Types

First of all you have to find out the script's type. Is it a batch script or a simulation script, or even a scripted daemon? Here are the differences:

  • Batch scripts are normally used to complete repetitive tasks, for example parameter changes, import of objects, applying colours, normalizing channels, object creation and manipulation, and so on. All these tasks do not need a simulation and they can be executed “offline”.
  • Simulation scripts are executed during a simulation and their main purpose is the manipulation and creation of particles. But, they are also used to influence object positions, RealWave surface, write maps, activate or deactivate nodes on demand, etc.
  • Scripted daemons introduce forces and apply them to fluids, and rigid and soft bodies.

 

Aside from these main types, there are three more scriptable nodes, but they are rarely used:

  • Scripted emitters
  • Scripted RealWaves
  • Scripted objects

Adding Scripts

For each script type, RealFlow provides a specific editor. Although these editor appear completely different, they have one thing in common: they are Python editors with exactly the same set of instructions. The difference is the point of execution. Batch scripts are triggered manually, simulation scripts can be executed at the beginning or end of a simulation, but also per frame or simulation step. Daemons, on the other hand, are applied automatically when it is safe to execute them.

 

Batch Scripts

Adding a batch script is a straight-forward process:

  • Layout > Batch Script
  • Copy/paste the script to the empty editor.
  • If the script has been saved to disk choose File > Open... from the editor's menu.




Simulation Scripts

There are few thing you should know about simulation scripts:

  • Layout > Simulation Flow
  • Choose, at which point of the simulation the script should be executed, e.g. “SimulationPre”, “StepPost”, or “FramesPost”.
  • Right-click on the appropriate entry, and choose “Add Script”.
  • Copy/paste the script to the empty editor.
  • If the script has been saved to disk choose File > Open... from the editor's menu.
  • The “Simulation Flow” window can remain open during simulation.

 

 

This decision, where to place a simulation script is not always easy to make.

  • “SimulationPre” is normally used to initialize values or define global variables.
  • The actual manipulation part is executed on frame or simulation step level.
  • You should always try to run a script at “FramesPre” to see if the simulation is stable. The reason is that it is much faster to execute a script once at every frame, or 100 times per frame at every simulation step.

 

Scripted Daemons

When you add a daemon script you have to decide to which node type it should be applied:

  • Daemons shelf > Scripted
  • Scripted01 > Node Params > Scripted > Edit

 

The editor provides a long list of pre-defined functions, introduced with a “def ...” statement. Now you have to decide which node you want to affect: emitters, (rigid and soft) bodies, Hybrido secondary elements, Hybrido domains etc. Again, mind leading spaces and tabs:

  • Copy/paste the script to the appropriate section of the editor.
  • If the script has been saved to disk choose File > Open... from the editor's menu.
  • The script editor window has to be closed during simulation and to get access to the underlying UI.