Move object to a position stored in an array

Move object to a position stored in an array

Anonymous
Not applicable
937 Views
3 Replies
Message 1 of 4

Move object to a position stored in an array

Anonymous
Not applicable

Hi,

 

I have a vector array that contains the positions of particles in a scene.

I would like to create spheres at every particle position.

Can someone tell me why this code isn't working? I'm getting "Error while parsing arguments", which isn't very informative.

 

int $numberOfParticles = `getAttr particleShape1.count`;
for ($i=0; $i <= $numberOfParticles; $i++) {
    polySphere -radius 0.2;
    move $particlesPos[$i];
}

particlesPos is the global array that contains the positions, and in itself it works fine (prints positions with no problem).

One note, I know I can use the instancer, but I'm trying to learn MEL so this is just an exercise.

0 Likes
938 Views
3 Replies
Replies (3)
Message 2 of 4

mspeer
Consultant
Consultant

Hi!

 

It's not good to post only a fraction of the code.

Use separated Translate values/variables , like "move $x $y $z".

0 Likes
Message 3 of 4

Anonymous
Not applicable

Thanks for your reply.

That's actually the whole code, there's nothing else to it.

 

Is there a way to directly access the single components of a vector that's inside a vector array, so that I can do what you suggested? I did manage to pull it off by breaking up X,Y,Z into separate variables, but this seems pretty inefficient:

 

int $particleCount = `getAttr particleShape1.count`;
int $myNum = 0;

for ($i=0; $i <= $particleCount; $i++) {
    polySphere -radius 0.2;
    vector $position = $particlePos[$myNum];
    float $xPos = $position.x;
    float $yPos = $position.y;
    float $zPos = $position.z;
    move $xPos $yPos $zPos;
    $myNum += 1;
    }
    

Is there anything akin to, theoretically: $particlePos[0].x?

0 Likes
Message 4 of 4

haggi_master
Advocate
Advocate

You can use

 

move $position.x $position.y $position.z;

 

 

0 Likes