Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Looping with the for ... in method is one of the most important concept concepts with RealFlow scripts, because this technique makes it possible to address individual particles, objects, simulation nodes, parameters, vertices, etc. Furthermore it is possible to count things, create indices, and many more

To do all these things RealFlow/Python offers several methods:

...

.

...

This construction is required if you want to loop through individual particles, nodes, vertices. In common terms: list elements. The notation is basically always the same, and only the type of scene element changes. Here are three examples:

Scene Nodes

Here is a loop for all nodes in a scene. There is no differentiation between domains, emitters, objects, daemons, etc.:

Code Block
# Mind the leading spaces. Without them you will get syntax errors!
allSceneNodes = scene.getNodes()
for singleNode in allSceneNodes:
	do something with singleNode, e.g. change one or more parameters
Scene Objects

Here is a loop for all nodes in a scene. The same principle is valid for daemons, domains, splines, cameras (scene.getDaemons(), scene.get_DY_Domains(), scene.getSplines(), scene.getCameras())., and so on:

Code Block
# Mind the leading spaces. Without them you will get syntax errors!
allSceneObjects = scene.getObjects()
for singleObject in allSceneObjects
	do something with singleObject, e.g. activate its rigid body dynamics feature
Dyverso Particles

Here is a loop for a dyverso domain's ("DY_Domain01") particles. The same principle is valid for Hybrido particles and standard particle emitters:

Code Block
#Mind the leading spaces. Without them you will get syntax errors!
dyversoDomain          = scene.get_DY_Domain("DY_Domain01")
dyversoDomainParticles = dyversoDomain.getParticles()
for singleParticle in dyversoDomainParticles:
	do something with singleParticle, e.g. get its age and delete it after a certain time

for .. in range(start, stop)

This type of loop is used if you want to specify a certain range.