Thursday, May 27, 2010

Combining 2 Particle Groups

//this procedure adds particles from one particle object to another.
//first select the object to add from, then add-select the object to add to.

global proc addParticles(){

string $particleObjs[] = `ls -sl`;
float $addPositions[] = `getAttr ($particleObjs[0]+".position")`;
int $countToAdd = size($addPositions)/3;;

string $emitCmd = ("emit -object " + $particleObjs[1] + "\n");
for ($i = 0; $i < $countToAdd; $i++){ int $xComp = $i*3; int $yComp = ($i*3)+1; int $zComp = ($i*3)+2; vector $addPos = <<($addPositions[$xComp]),($addPositions[$yComp]),($addPositions[$zComp])>>;
$emitCmd += " -pos "+$addPos+"\n";


So, open a text editor and paste the code in there and save the file as "addParticles.mel".
Place the file in your maya scripts directory.
On Windows the default place would be:
C:\Documents and Settings\\My Documents\maya\scripts\

Then start or restart maya. In the outliner select the particle object you want to add from, and then add-select the particle object you want to add to. Then type addParticles in your MEL command line and hit enter. Done.

The particles from the first object are added at the same positions they had in their own object. And the original object is not deleted, but you can do that or hide it to verify that the first object now includes all particles.


No comments:

Post a Comment