hybrido scripting?

Discussion about scripting with Python
darkczar
Posts: 32
Joined: Thu Sep 08, 2011 4:34 pm

hybrido scripting?

Postby darkczar » Sat Jan 18, 2014 2:11 am

Is it possible to loop over the particles in a hybrido (or hybrido2) grid domain? I can't figure out the syntax, or find any examples. This doesn't work for me:

def onSimulationStep():
em = scene.getGridDomain("Grid_Fluid_Domain01")
p = em.getFirstParticle()


darkczar
Posts: 32
Joined: Thu Sep 08, 2011 4:34 pm

Re: hybrido scripting?

Postby darkczar » Sat Jan 18, 2014 2:13 am

I have indented the last two lines. I don't know why they are formatted incorrectly in my post above.

User avatar
tsn
Posts: 915
Joined: Fri Oct 27, 2006 10:36 am

Re: hybrido scripting?

Postby tsn » Sat Jan 18, 2014 10:47 am

Here you are:

Code: Select all

emitter = scene.get_HY_GridDomain("HY_Domain01")
particleList = emitter.getParticles()
for particle in particleList:
   ...do something here


The example is for Hybrido 2.

darkczar
Posts: 32
Joined: Thu Sep 08, 2011 4:34 pm

Re: hybrido scripting?

Postby darkczar » Tue Jan 21, 2014 2:39 pm

Thanks!

Next question:

I can use the normal
"particle = particle.getNextParticle()"

right?

I seem to have an error in my little script, at the bold red line. Here it is, fwiw, (without the indenting):

emitter = scene.get_HY_GridDomain("HY_Domain_v16")
particleList = emitter.getParticles()
f = scene.getCurrentFrame()
increment = 0.70
threshold = 0.3
minlife = 0.50
if (f > 4):
for particle in particleList:
velocity = particle.getVelocity()
age = .4 #particle.getattr("Age")
velo_x, velo_y, velo_z = velocity.getX(), velocity.getY(), velocity.getZ()
new_velocity = Vector.new(velo_x * increment, velo_y * increment, velo_z * increment)
zero_velocity = Vector.new(0.0, 0.0, 0.0)
if (age <= minlife):
particle = particle.getNextParticle()
elif (velocity.module() < threshold):
# particle.setVelocity(zero_velocity)
particle.freeze()
particle = particle.getNextParticle()
else:
particle.setVelocity(new_velocity)
particle = particle.getNextParticle()

User avatar
tsn
Posts: 915
Joined: Fri Oct 27, 2006 10:36 am

Re: hybrido scripting?

Postby tsn » Tue Jan 21, 2014 3:32 pm

You have to use either the "getFirstParticle…while…getNextParticle" method or the "for…in" method. In your script, both methods are mixed up and therefore it won't run.

I assume you want just want to go on in the script without doing anything in code segment below, right?

Code: Select all

if (age <= minlife):
   particle = particle.getNextParticle()

Change this to:

Code: Select all

if (age <= minlife):
   pass

The last line (particle = particle.getNextParticle()) is also not correct here and must be deleted. The "for…in" method allocates more memory, but is faster. That's why I suggested that approach.

darkczar
Posts: 32
Joined: Thu Sep 08, 2011 4:34 pm

Re: hybrido scripting?

Postby darkczar » Tue Jan 21, 2014 3:40 pm

Will do! thanks!

darkczar
Posts: 32
Joined: Thu Sep 08, 2011 4:34 pm

Re: hybrido scripting?

Postby darkczar » Tue Jan 21, 2014 4:42 pm

Ugh. I simplified it a little bit, but I am getting an error at "freeze". When editing it doesn't want to auto-complete "freeze" but only "frozenSet()".

General question: Where is there an alphabetical list of realflow expression functions that I can look at to see what is available, what each function does, arguments it takes, etc?

Anyway, anyone know why this is erroring out on "freese()". Can I freeze gridDomain particles?:

emitter = scene.get_HY_GridDomain("HY_Domain_v16")
particleList = emitter.getParticles()
f = scene.getCurrentFrame()
increment = 0.70
threshold = 20.0
zero_velocity = Vector.new(0.0, 0.0, 0.0)
if (f > 2):
for particle in particleList:
velocity = particle.getVelocity()
new_velocity = Vector.new(velo_x * increment, velo_y * increment, velo_z * increment)
if (velocity.module() < threshold):
particle.freeze()
else:
velo_x, velo_y, velo_z = velocity.getX(), velocity.getY(), velocity.getZ()
particle.setVelocity(new_velocity)

darkczar
Posts: 32
Joined: Thu Sep 08, 2011 4:34 pm

Re: hybrido scripting?

Postby darkczar » Tue Jan 21, 2014 7:10 pm

particle.setVelocity() throws an error as well.

User avatar
tsn
Posts: 915
Joined: Fri Oct 27, 2006 10:36 am

Re: hybrido scripting?

Postby tsn » Wed Jan 22, 2014 8:14 am

It's unfortunately not possible to modify Hybrido particles' velocity for technical reasons and this also applies for the freeze() command. The reason is that there's a complex relationship between the particles' velocity and the underlying grid. If you were changing velocity, the solver would become unstable. To avoid this, the velocity part is calculated exclusively by the solver.

For a complete Python reference go to Help > Contents… On the left you can see a tree structure with an entry called "Scripting Reference". Expand it, and you'll see a list of the available classes.

darkczar
Posts: 32
Joined: Thu Sep 08, 2011 4:34 pm

Re: hybrido scripting?

Postby darkczar » Wed Jan 22, 2014 3:42 pm

Thanks for the reply. I'll stop banging my head against the wall! haha!

What about force? Can I script that? I just want the fluid to stop moving. I've got a great looking sim, I just need it to stand still long enough that I can loock off the frame and hold it. As it is now, the mesh chatters and sizzles. I'm getting decent results with particles, too, but if I can just get the hybrido 2 fluid to stand still for a few frames, I'll be done.

(For some reason the help -> contents is empty this morning, but thanks for the tip. I am keen to rtfm, if I can find it! haha.)

thanks!


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 3 guests