convert string array to float MEL

Viewed 196

I having a trouble with a code in MAYA 2020.

  • I want to create a new expression into a default value of a Arnold aiUserDataInt

  • I need the default value of a aiUserDataInt = attribute from a geometry that I crate name "ID"

so, my code looks like this:

string $Selected[] = `ls -selection`;

for ($node in $Selected)

aiUserDataInt1.default = $Selected.id;

but I have these error:

// Error: Line 2.37: Cannot cast data of type string[] to float. //

So, I suppose default value do not accept arrays

my question would be: is there a way to convert array into float?

or what am I doing wrong?

Thanks in advance

1 Answers

Unfortunately that's not how mel works. You can do:

string $Selected[] = `ls -selection`;
for ($node in $Selected)
{
   int $id = getAttr($node + ".id");
   setAttr("aiUserDataInt1.default", $id);
}

Didn't test it, but it should work like this. You get and set attributes with getAttr() and setAttr().

Related