Versions Compared

Key

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

Another exciting and very useful feature is the definition of particular attributes, created by the user. There are many cases where it is necessary to add an attribute that is not part of RealFlow’s Python interface by default. To make use of this function, RealFlow offers a couple of new instructions, exclusively valid for emitters and particles:

  • Emitters: createParticlesAttribute, destroyParticlesAttribute, queryParticlesAtrribute
  • Particles: setAttribute, getAttribute, queryAttribute

The first step is to create a particle attribute and this action requires two arguments. The first one is a unique “name” in form of an integer, the other one’s the expected data type. 
Allowed types are:

PARTICLEPARTICLE_ATTR_TYPE_DOUBLE, PARTICLE_ATTR_TYPE_INT, PARTICLE_ATTR_TYPE_BOOL and PARTICLE_ATTR_TYPE_VECTOR


So, first of all it is necessary to create an attribute for an emitter which will then be applied to a particle: 

Code Block
themeEclipse
languagepython
linenumberstrue
# Write this part to SimulationPre

emitter = scene.getEmitterget_PB_Emitter("Circle01")
emitter.createParticlesAttribute(100, PARTICLE_ATTR_TYPE_DOUBLE)
emitter.createParticlesAttribute(101, PARTICLE_ATTR_TYPE_INT)
emitter.createParticlesAttribute(102, PARTICLE_ATTR_TYPE_BOOL)
emitter.createParticlesAttribute(103, PARTICLE_ATTR_TYPE_VECTOR)

# Write this part to FramePre

emitter      = scene.get_PB_Emitter("Circle01")
particleList = emitter.getParticles()

for particle in particleList:
    particle.setAttribute(100, 3.14159)
    particle.setAttribute(101, 5)
    particle.setAttribute(102, True)
    particle.setAttribute(103, Vector.new(1.0,0.0,1.0))

...

Code Block
themeEclipse
languagepython
linenumberstrue
emitter = scene.get_PB_Emitter("Circle01")
flag    = emitter.queryParticlesAttribute(102)

if (flag):
    scene.message("This attribute exists!")

...

 

For a requesting a particle’s attribute, everthing has to be inside a loop again. In this example it is a while-loop:

...