2

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

cursorrux
  • 1,382
  • 4
  • 9
  • 20

1 Answers1

0

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().

haggi krey
  • 1,885
  • 1
  • 7
  • 9
  • Hi tnks for the answer, but Unfortunately, that code get an error: // Error: line 3: No object matches name: aiUserDataInt1.id // // Error: line 0: An execution error occured in the expression expression3. // // Result: expression3 // sorry I´m a newbie programing – Guillermo Vaca Nuñez Sep 11 '21 at 15:29
  • If you get this error, you selected the aiUserDataInt1 node and executed the script. You have to select your object and exectute the script. – haggi krey Sep 12 '21 at 11:01