Oct 2018
1 / 5
Oct 2018
Oct 2019

Hello.

I've been trying to learn MEL. But the way it works is driving me crazy.
So I have a particle system. It is emitting through a Mesh. And I added a "per point emission rates" to my mesh. So that I can adjust the emission rates individually. The attribute looks like this:
pPlaneShape1.emitter1RatePP[0]
Because my mesh is large I want to write a script that assigns random numbers between 0 and 1 to every vertex emitter1RatePP position.

My question is;
When I write this it assigns a random number to position 0. So it works fine.
$min = 0;
$max = 1;
$random = rand($min, $max);
setAttr"pPlaneShape1.emitter1RatePP[0]" $random;

But when I use a variable as the position it won't work:
$min = 0;
$max = 1;
$var = 0;
$random = rand($min, $max);
setAttr"pPlaneShape1.emitter1RatePP[$var]" $random;

The error I am getting is this:

// Error: line 6: setAttr: Invalid attribute name: pPlaneShape1.emitter1RatePP[$var] //
// Error: line 0: An execution error occured in the expression randomEmmision_Attr. //
// Result: randomEmmision_Attr //

If I can figure this out than I'll write a for loop and use the iterator as a position.

I'd really appreciate any help. Thanks:)

  • created

    Oct '18
  • last reply

    Oct '19
  • 4

    replies

  • 2.3k

    views

  • 4

    users

  • 1

    link

Hi,
vertex emitter1RatePP position corresponds to $var.
If you assign that to $var in a loop it will work.
Regards,
Prem

Hello shinyprem,
Thanks for your reply! I really appreciate it:)

If I understood correctly you asked me to make an adjustment like this:
$min = 0.02;
$max = 0.5;
$random = rand($min, $max);
for ($i = 0; $i < 10; $i++)
{
setAttr"pPlaneShape1.emitter1RatePP[$i]" $random;
}

I still get this error when I try to assign a value that is initialised inside of a for loop:

expression -e -s "$min = 0.02;\n$max = 0.5;\n\n$random = rand($min, $max); \n\nfor ($i = 0; $i < 10; $i++)\n{\n\t$var = 5;\n\tsetAttr\"pPlaneShape1.emitter1RatePP[$var]\" $random;\n}" -o "" -ae 1 -uc all randomEmmision_Attr;
// Error: line 8: setAttr: Invalid attribute name: pPlaneShape1.emitter1RatePP[$var] //
// Error: line 0: An execution error occured in the expression randomEmmision_Attr. //
// Result: randomEmmision_Attr //

This seems really odd to be honest.

Hi
I think Your syntax on setAttr is wrong.
Eg.
setAttr (pPlaneShape1.visibility) 0 ;
Regards,
Prem

2 months later

You're using a string plus a variable and should be written as:

setAttr("pPlaneShape1.emitter1RatePP[" + $i + "]");