Using the Variables
In the second stage all the entered or default values are translated into individual variables and can now be treated as any other variable and used for further calculations. Here, the emitter is created with a series of setParameter()
statements.
standard_emitter = scene.add_PB_Emitter(emitter_types[emitter_type]) standard_emitter.setParameter("Type", particle_types[particle_type]) standard_emitter.setParameter("Resolution", resolution) standard_emitter.setParameter("Density", density) standard_emitter.setName(name) if (particle_type != 2): standard_emitter.setParameter("Int Pressure", intpres) standard_emitter.setParameter("Ext Pressure", extpres) standard_emitter.setParameter("Viscosity", viscosity) standard_emitter.setParameter("Surface Tension", tension)
This code section needs some further explanation. The first issue concerns the results from the list fields and you can see a certain notation there in the argument:
(emitter_types[emitter_type])
The reason is that the corresponding field from GUI hands over an integer instead of a string, for example “Circle” or “Cylinder”. This selected emitter type is translated into a number and then used to find the corresponding entry in the emitter_types
list. With “particle_types” it is exactly the same mode of operation.
Finally, you can see this if-condition:
if (particle_type != 2):
It became necessary to introduce this differentation, because elastic particles do not provide parameters, like “Int Pressure”, “Ext Pressure”, “Viscosity” and “Surface Tension”. These settings are now only changed for non-elastic fluid types. The “!=” operator means
if particle_type is not 2
With the execution of the last statement, the emitter appears under "Nodes" with all previously defined settings and the script is finished. A program like that is perfectly suited for the batch scripts window. Another idea would be to add it to RealFlow’s scripts toolbar with a nice icon. From there it can be launched with a single mouse click.