Community
Maya Forum
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

pass array values to extra attributes

1 REPLY 1
Reply
Message 1 of 2
Kaushik92022
93 Views, 1 Reply

pass array values to extra attributes

$objs = `ls -sl`;
print $objs[0];

// the array to iterate through
float $data_array[] = {0.13,0.41,0.32};

int $NoOfParameters = 3;

string $PartName;

string $ParameterNames;

$ParameterNames[] = stringToStringArray{"p1 p2 p3 p4 p5 p6 p7 p8 p9 p10"};
print ($ParameterNames[0]);

 

// each time the loop repeats, $item will hold the next element in the array
for( $i = 0; $i< $NoOfParameters; $i++ )
{

//to test the $data_array//

print($data_array[$i] + "\n");

$PartName = ($objs[$i] + "." + $ParameterNames[$i]);
print $PartName;
setAttr $PartName $data_array[$i];
print($data_array[$i] + "\n");
}

 

Output:

// Error: $ParameterNames[] = stringToStringArray{"p1 p2 p3 p4 p5 p6 p7 p8 p9 p10"};
//
// Error: Line 13.17: Syntax error //
// Error: print ($ParameterNames[0]);
//
// Error: Line 14.26: "$ParameterNames" is not an array. //
// Error: $PartName = ($objs[$i] + "." + $ParameterNames[$i]);
//
// Error: Line 24.52: "$ParameterNames" is not an array. //

 

Please any one can solve this issues.

1 REPLY 1
Message 2 of 2
brian.kramer
in reply to: Kaushik92022

Hi,

Here are some things I noticed in your script.

  • Your first line: $objs = `ls -sl`; hasn't defined $objs as a string array correctly. It should be: string $objs[] = `ls -sl`; When you define a variable the type comes first, followed by the variable name, and lastly (in the case of an array) followed up with []. Note your definition and initialization of $data_array is correct.
  • Instead of hardcoding the size of your array you could use: int $NoOfParameters = size($data_array);
  • You need to indicate your $ParameterNames variable is an array by appending []. Try: string $ParameterNames[];
  • When you set a variable which is an array you don't include []. You only use [] when defining the variable or accessing an element in the array. Your line should be $ParametersNames = stringToStringArray(...);
  • Lastly, when calling stringToStringArray(...) you need to provide two arguments: the string to separate and the separation string, in your case it will be space. Try: $ParameterNames = stringToStringArray("p1 p2 p3 p4 p5 p6 p7 p8 p9 p10", " ");

Hope this helps.

 


Brian Kramer
Software Developer

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report