PDA

View Full Version : A MEL problem.


ovspianist
11-23-2008, 12:47 PM
This is not about instancer.

I have a particle shape which contains about 30 particles controlled by a couple of fields, and I have the same amount of simple boxes.
Now I want to put each individual particle's world position values into the boxes, one for one, without using particle instancer.I'm really confused about how to transfer the per particle array data to an transform node. By the way, all my boxes are carefully named so that they have the same prefix.

Thanks a lot!

Aikiman
11-23-2008, 08:08 PM
Here's the basic syntax that seems to pull it off... works with equal number of objects > particles.


string $select[] = `ls -sl`;
$pCount = `particle -q -ct particle1`;
int $i;
for ($i = 0; $i< $pCount; $i++){
float $pos[] = `getParticleAttr -at position ("particleShape1.pt[" +$i+ "]")`;
setAttr ($select[$i] + ".translateX") ($pos[0]);
setAttr ($select[$i] + ".translateY") ($pos[1]);
setAttr ($select[$i] + ".translateZ") ($pos[2]);

}


If you have less objects than particles then change the for loop to...

for ($i = 0; $i< size($select); $i++)

Also my code only works if you have your objects selected but you can replace $select with the name of your objects and hard code it in instead.
hope that helps.





This is not about instancer.

I have a particle shape which contains about 30 particles controlled by a couple of fields, and I have the same amount of simple boxes.
Now I want to put each individual particle's world position values into the boxes, one for one, without using particle instancer.I'm really confused about how to transfer the per particle array data to an transform node. By the way, all my boxes are carefully named so that they have the same prefix.

Thanks a lot!

ovspianist
11-23-2008, 10:42 PM
It's really not a long one...

Thanks, Aikiman!
I'll try it out.

ovspianist
11-25-2008, 02:28 AM
Here's the basic syntax that seems to pull it off... works with equal number of objects > particles.


string $select[] = `ls -sl`;
$pCount = `particle -q -ct particle1`;
int $i;
for ($i = 0; $i< $pCount; $i++){
float $pos[] = `getParticleAttr -at position ("particleShape1.pt[" +$i+ "]")`;
setAttr ($select[$i] + ".translateX") ($pos[0]);
setAttr ($select[$i] + ".translateY") ($pos[1]);
setAttr ($select[$i] + ".translateZ") ($pos[2]);

}


If you have less objects than particles then change the for loop to...

for ($i = 0; $i< size($select); $i++)

Also my code only works if you have your objects selected but you can replace $select with the name of your objects and hard code it in instead.
hope that helps.



Oh, just thought of one thing... Will this work as an expression?

Aikiman
11-25-2008, 02:35 AM
Yes it should just make sure you have your cubes selected. If you dont want to do it that way then hard code the cube names into the script.

ovspianist
11-25-2008, 11:17 AM
Yes it should just make sure you have your cubes selected. If you dont want to do it that way then hard code the cube names into the script.

Ok... Thanks again!

CGTalk Moderation
11-25-2008, 11:17 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.