Meltscript Standard particles -> Dyverso

Discussion about scripting with Python
geri_meyer
Posts: 4
Joined: Wed Feb 15, 2017 10:27 am

Meltscript Standard particles -> Dyverso

Postby geri_meyer » Fri Feb 24, 2017 2:07 pm

Hello you guys,

Could someone in here help me with getting this melting script work for Dyverso? RF informs me that there's a script error regarding the "getFirstParticle" statement. I can imagine that there are other errors aswell, since this is a script designed to work with standard particles.

This is the script (the DY statements are my adjustments on the script):

def onSimulationBegin():
emitter = scene.get_DY_Emitter("DY_Emitter01")
particle = emitter.getFirstParticle()
while (particle):
particle.setVelocity(Vector.new( 0,0,0 ))
particle.freeze()
particle = particle.getNextParticle()



def onSimulationFrame( frame ):
numNeighbors = {}
emitter = scene.get_DY_Emitter("DY_Emitter01")
particle = emitter.getFirstParticle()
# speed Multiplier
sVal = 50
while (particle):
numNeighbors[int(particle.id)]=len(particle.getNeighbors(.5))
particle = particle.getNextParticle()
i=0
for id, n in sorted(numNeighbors.items(), key=lambda x:x[1]):

if i < frame*sVal:
emitter.getParticle(id).unfreeze()
i+=1

Many thanks for any advise!

Best regards,

Geri


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

Re: Meltscript Standard particles -> Dyverso

Postby tsn » Fri Feb 24, 2017 4:37 pm

Hi Geri,

Unfortunately, this script won't work with Dyverso, because the freeze() and unfreeze( ) commands are only available for standard particles, not for Dyverso. It's the same with getFirstParticle() and getNextParticle( ) - only for standard SPH. Another thing is that it's the domain that keeps the particles in Dyverso, not the emitter. Finally you have to mind the indents: after every colon ( : ) you need a tab, otherwise you'll get tons of syntax errors.

Loops in Dyverso have to be done with the following syntax:

Code: Select all

domain = scene.get_DY_Domain("DY_Domain01")
particles = domain.getParticles()

for singleParticle in particles:
      ... do something here


The old getFirst/getNextParticle() syntax was less memory-consuming, but slower. And if I have the choice between RAM and speed I always go for speed - at least in Python ;)

geri_meyer
Posts: 4
Joined: Wed Feb 15, 2017 10:27 am

Re: Meltscript Standard particles -> Dyverso

Postby geri_meyer » Fri Feb 24, 2017 6:07 pm

Hi tsn,

Sorry to hear that, but thank you anyway for your detailed and quick reply!

I'll look at another way of solving my problem.

Thanks again!

Have a great day,

Regards,

Geri

alex
Posts: 37
Joined: Tue May 25, 2010 1:18 pm

Re: Meltscript Standard particles -> Dyverso

Postby alex » Wed Mar 01, 2017 8:21 am

Hi Geri,

I just answered you in the official RealFlow forum (sorry, your post got unnoticed among tons of spam).

I basically recommend you to have a look at this very simple tutorial:
https://vimeo.com/130636904
RealFlow Team
Next Limit Technologies


Return to “Python-Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest