How do I add components to an existing array in mel?

How do I add components to an existing array in mel?

malcolm_341
Collaborator Collaborator
651 Views
4 Replies
Message 1 of 5

How do I add components to an existing array in mel?

malcolm_341
Collaborator
Collaborator

I can't seem to figure this out, I thought this would work, but it gives an error.

 

string $UVs[] = {};

$UVs = $UVs[0] + $moreUVs[0];

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

jmreinhart
Advisor
Advisor
string $UVs[] = {"A"};
string $moreUVs[] = {"B"};
$UVs[size($UVs)] = $moreUVs[0];
print $UVs;

In generalyou need to add each value one by one. There are some MEL commands for dealing with string arrays specifically though:

 

https://download.autodesk.com/us/maya/2009help/Commands/appendStringArray.html 

0 Likes
Message 3 of 5

malcolm_341
Collaborator
Collaborator

@jmreinhart 

Thanks for your reply, before posting I tried the appendStringArray and it didnt work with components, only text strings, unless I was using it wrong. Could you post an example of starting with an empty array and then adding some verts to it from another existing array.

0 Likes
Message 4 of 5

Kahylan
Advisor
Advisor
Accepted solution

Hi!

How are you declaring the vertexes that you want to add to your array? Most commands will give you an array of strings.

Here's an example of storing selected vertices in an empty array:

string $store[] = {};
string $vert[] = `ls -sl -fl`;
appendStringArray($store, $vert, size($vert));
print($store);

 

I hope this helps!

Message 5 of 5

malcolm_341
Collaborator
Collaborator

Oh I see how it works now, thanks for the example that makes sense.

0 Likes