AWS Thinkbox Discussion Forums

Magmascript - Get current particle count

Hi all,

What’s the easiest way to get the particle count of the current object in magmascript? This would be the largest ID of all the particles.

MagmaScript is the name of the Magma flow file saved by the editor. Did you mean to say “Magma”, or did you mean via the MAXScript interfaces when scripting particle I/O operations?

Ah sorry, I meant in the Magma Flow Editor.

Unfortunately, currently there is no way to know the total number of particles in the stream. In many cases, the PRT stream itself does not know the actual count (e.g. PRT Volume etc.) until it is generated, and the viewport and render counts are usually different.

Magma evaluation normally does not require any knowledge of the total count of particles to be processed.
We have a wish list item logged against this, and we already have a MAXScript function ready for an upcoming update build that lets you query the count of a PRT Stream when scripting (this is why I asked for clarification). I am not sure how exactly we would implement this for Magma, and we also have to keep track of what is happening to the stream as it moves up the stack if there are Selections and Krakatoa Delete modifiers… So it won’t be trivial, and might end up quite slow.

Right now your best bet is to figure out the count with other methods, and specify it via an InputValue (and possibly keyframe the value if the count is changing over time). You could write a MAXScript that, for a given time interval, saves the particles to a temp. file, checks the count of the resulting PRT file, keyframes the value (or collects the values in a text file or in a persistent global array or something), and then deletes the temp. file.

It is quite hacky, but if you need the value, you can set that up…

Thanks as always for the tip Bobo!

I am trying to make some creative animations with Magma, and it sounds like this may not be the best approach.

I was hoping to set up a script to target a “sliver” of the overall particles and change their emission. Using the total count and IDs, I could find particles within a range and mess with their channels. I ended up getting it to work by making the total an input value but it only looked half as cool as I was hoping.

I think I might try the same thing by using lifespan next.

Privacy | Site terms | Cookie preferences