Looping - Particles
Dyverso Domains
Add the script to Simulation Flow (Ctrl/Cmd + F2)Â > FramesPre or StepsPre.
Get all particles from "DY_Domain01" and delete them when their velocity is greater than 5.0 m/s.
# Get the domain "DY_Domain01" and its particles dyversoDomain = scene.get_DY_Domain("DY_Domain01") dyversoParticles = dyversoDomain.getParticles() Â # Loop through every individual particle and delete it if its velocity is greater than 5.0 m/s for particle in dyversoParticles: if (particle.getVelocity().module() > 5.0): dyversoDomain.removeParticle(particle.getId())
Hybrido Domains
Add the script to Simulation Flow (Ctrl/Cmd + F2) > FramesPre or StepsPre.
Most attributes of Hybrido core fluid particles are controlled by the solver and cannot be changed, but it is possible to trigger certain events, e.g. to increase the Hybrido emitter's "Speed" parameter dynamically:
# Initialize the required values # Get the domain "HY_Domain01" and its particles, get the emitter "HY_Emitter01" # Read out the emitter's "Speed" parameter and the current number of particles hybridoDomain = scene.get_HY_GridDomain("HY_Domain01") hybridoEmitter = scene.get_HY_Emitter("HY_Emitter01") hybridoParticles = hybridoDomain.getParticles() emitterSpeed = hybridoEmitter.getParameter("Speed") numOfParticles = len(hybridoParticles) currentVelocity = 0.0 maxSpeed = 5.0 # Sum up all velocities for particle in hybridoParticles: currentVelocity += particle.getVelocity().module() # Calculate average velocity and avoid illegal division by zero: Â if (numOfParticles > 0): averageVelocity = currentVelocity / float(numOfParticles) # Check, if average velocity is greater than current emitter speed and less than the given speed limit "maxSpeed"Â if (averageVelocity > emitterSpeed and averageVelocity <= maxSpeed): hybridoEmitter.setParameter("Speed", averageVelocity)
Standard Particle Fluid Emitters
Add script to Simulation Flow (Ctrl/Cmd + F2) > FramesPre or StepsPre.
Get all particles from "Circle01" and delete them when their velocity is greater than 5.0 m/s.
"for ... in" Method
# Get the standard particle emitter "Circle01" and its particles standardEmitter = scene.get_PB_Emitter("Circle01") standardParticles = standardEmitter.getParticles() Â # Loop through every individual particle and delete it if its velocity is greater than 5.0 m/s for particle in standardParticles: if (particle.getVelocity().module() >= 5.0): standardEmitter.removeParticle(particle.getId())
"while ... next" Method
# Get the standard particle emitter "Circle01" and its first particle standardEmitter = scene.get_PB_Emitter("Circle01") particle = standardEmitter.getFirstParticle() # Loop through every individual particle and delete it if its velocity is greater than 5.0 m/s while (particle): if (particle.getVelocity().module() >= 5.0): standardEmitter.removeParticle(particle.getId()) # Get the emitter's next particle particle = particle.getNextParticle()