Creating curves from nParticle motion

Creating curves from nParticle motion

Parmenides
Collaborator Collaborator
527 Views
4 Replies
Message 1 of 5

Creating curves from nParticle motion

Parmenides
Collaborator
Collaborator

As the title says I am trying to create curves from nParticles. With a little turbulence they make great organic lines. 

 

I found this tutorial that shows just that, but there have been changes to MEL since 2016 apparently.  https://www.youtube.com/watch?v=yiLZAz1L41M&t=349s

 

It works by creating a curve segment every 5 frames. The script bits go in the nParticleShape node/Per Particle (Array) Attributes. 

 

I get errors about attributes not found.  Can someone with more experience help me with this?  Thanks. 

 

Here is the original code: 

 

CREATION:

vector $pos = particleShape1.position;
string $curveName = "curve_" + particleShape1.particleId;
int $objTest = `objExists $curveName`;
if ($objTest == 1)
{
delete $curveName;
}
curve -p ($pos.x) ($pos.y) ($pos.z) -n $curveName;

 

RUNTIME:

vector $pos = particleShape1.position;
string $curveName = "curve_" + particleShape1.particleId;
if (frame/5 == trunc(frame/5))
{
curve -append -p ($pos.x) ($pos.y) ($pos.z) $curveName;
}

 

 

0 Likes
Accepted solutions (1)
528 Views
4 Replies
Replies (4)
Message 2 of 5

Kahylan
Advisor
Advisor
Accepted solution

Hi!

 

The issue is with the naming of the attributes you are trying to get values from. You are using "particleShape1" instead of "nParticleShape1" which is the default name of the shape of an nParticle. If you renamed your particle, you can find the name of the shape in the attributeeditor and just copy that name into your script.

 

This worked for me (Maya 2022.4)

Creation:

 

vector $pos = nParticleShape1.position;
string $curveName = "curve_" + nParticleShape1.particleId;
int $objTest = `objExists $curveName`;
if ($objTest == 1)
{
delete $curveName;
}
curve -p ($pos.x) ($pos.y) ($pos.z) -n $curveName;

 

Runtime bd:

 

vector $pos = nParticleShape1.position;
string $curveName = "curve_" + nParticleShape1.particleId;
if (frame/5 == trunc(frame/5))
{
curve -append -p ($pos.x) ($pos.y) ($pos.z) $curveName;
}

 

 

Also note that since you are using an expression to do this, you need to have the nParticleShape selected while creating the expression, otherwise it wont find the attributes either.

 

I hope it helps!

Message 3 of 5

Parmenides
Collaborator
Collaborator

Thanks Kahylan.  I had earlier tried changing to nParticle1 but figured there must be another issue as well.  I tried your suggestion in 2022.4 and 2023.3 and I couldn't  get it to work. I reset my prefs, still no go.  Then I tried it on another machine and still couldn't get it to work. When I hit Create I get the curves in the outliner though.  I wonder if when you post the code there is character being switched or something? 

0 Likes
Message 4 of 5

Parmenides
Collaborator
Collaborator

Finally figured it out.  I had it right to begin with. Once I turned off the Evaluation Cache, the curves will show up if I select them in the outliner. Otherwise they won't become visible. Another day wasted because of Maya weirdness. 

 

Really appreciate your help with this. If helps to know that if someone else gets it to work then it is just figuring out what I have different.  

0 Likes
Message 5 of 5

Kahylan
Advisor
Advisor

Ah yes, Evaluation cache messes with expressions, didn't think about that since I have that feature turned off by default

0 Likes