To calculate the maximum number of particles that your scene had, like we did in class here is what you do.
In the expression editor, set the Select Filter to "by Script Node name" and type in "particleCountNode" in the Script Node name entry box. Then enter this code in the Script section:
global float $particleMax;
float $ptMax;
if ( `currentTime -query` == 1 ) {
$particleMax = 0;
}
for ($particle in (`ls -typ particle`))
{
//print ($particle + "\n");
$ptMax = `particle -q -ct $particle`;
//print ($ptMax + "\n");
if ( $ptMax > $particleMax ) {
$particleMax = $ptMax;
}
};
print ("MAXIMUM NUMBER OF PARTICLES IN SCENE: = " + $particleMax + "\n");
If you play your scene from the beginning all the way through the end then you will see the max number of particles printed in the script editor at the end.
This could be done a bunch of different ways but this is a quick and simple method to get you started.
Now I'm modifying this to
Now I'm modifying this to track a curve and keyframed locator.
A bug exists in rewinding.
global float $particleMax;
global string $particleCurve;
global string $particleTotalLocator1[];
float $frTotal = 0;
if ( `currentTime -query` == 1 )
{
$particleMax = 0;
if ( `objExists $particleCurve` ) { curve -r -p 0 0 0 $particleCurve;
} else { $particleCurve = `curve -p 0 0 0`;
}
$particleTotalLocator1 = `spaceLocator`;
}
for ($particle in (`ls -typ particle`)){ $frTotal += `particle -q -ct $particle`; };
if ( $frTotal > $particleMax ) { $particleMax = $frTotal; }
print ("Frame Particle Total Count = " + $frTotal + "\n");
curve -a -p `currentTime -query` $frTotal 0 $particleCurve;
move -a `currentTime -query` $frTotal 0 $particleTotalLocator1;
setKeyframe $particleTotalLocator1.translateX;
print ("MAXIMUM NUMBER OF PARTICLES IN SCENE: = " + $particleMax + "\n");
Ok I didn't like the
Ok I didn't like the keyframed locator. It wouldn't save out in batch. It was only good for interactive use. Here is a modification that works in batch and generates a csv file that you can load into and excel and graph to your hearts content.
Make sure you make a scriptNode out of this with the expression editor and set it to execute on Before TimeChange. The other caveat is that you need a logs directory inside your project directory. But you already have that right!!! You should be storing your batch log files in that log directory anyway
global float $pMax;
global int $cvFileID;
global string $cvFileName;
float $frTotal = 0;
string $projDir = `workspace -q -rd`;
$projDir += "logs/";
if ( `currentTime -query` == 1 ) {
$pMax = 0;
string $starTtimedate = `date -format "MM_DD_YYYY_hh_mm_ss"`;
$cvFileName = $projDir +"ParticleCountCurve_" + $starTtimedate + ".csv";
$cvFileID = `fopen $cvFileName "w"` ;
} else {
$cvFileID = `fopen $cvFileName "a"`;
}
for ($particle in (`ls -typ particle`)){ $frTotal += `particle -q -ct $particle`; };
if ( $frTotal > $pMax ) { $pMax = $frTotal; }
print ("Frame Particle Total Count = " + $frTotal + "\n");
string $t2 = (`currentTime -query` + "," + $frTotal + "\n");
fprint $cvFileID $t2;
fclose $cvFileID;
[G2:2812 n=1 size=720]
You should get something like this when you graph it in excel.