Mel how to select same faces from current array, but on another object?

Mel how to select same faces from current array, but on another object?

malcolm_341
Collaborator Collaborator
1,838 Views
4 Replies
Message 1 of 5

Mel how to select same faces from current array, but on another object?

malcolm_341
Collaborator
Collaborator

I've often run into this problem where I've got an array of face stored in a variable, but I want to substitute a new object name. I've seen this accomplished online, but I don't understand the code because it's written in short hand. Could someone help me figure this out.

 

//Store faces from first object
string $components[] = `ls -sl -fl`;

//Get name of second object manually select here this is just an example
string $obj[] = `ls -sl`;

//Loop through array swap names
string $newComponentSel[] = {};
for ($item in $components)
{
	string $comp = `match "\\..+" $item`;
	$newComponentSel[size($newComponentSel)] = ($obj[0] + $comp);
}
select $newComponentSel;

 This code works, but I don't understand the second line $newComponenSel[size($newComponentSel)] could someone write that out for me in long hand?

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

stuzzz
Collaborator
Collaborator

Hello Malcolm,

 

$newComponentSel[size($newComponentSel)] = ($obj[0] + $comp);

The line above is in a forLoop as you can see so anytime the loop iterate, the variable $newComponentSel which is an array has a new value. 

It looks like a trick to append a new value ($obj[0]+$comp) at the end of the $newComponentSel array.

 

Message 3 of 5

malcolm_341
Collaborator
Collaborator
$newComponentSel[size($newComponentSel)]

What do the square brackets do, I haven't worked with those before?

0 Likes
Message 4 of 5

stuzzz
Collaborator
Collaborator
Accepted solution

The brackets means "the value at this nth index of this variable".

let's say you have this array:

string $myVar[]= {"banana", "toto", "titi"};
print $myVar[0]; // will return the first value which is "banana"
print $myVar[1]; // will return the next value which is "toto"
print $myVar[2]; // will return the last value which is "titi"
print $myVar[size($myVar)-1]; // will return the last value, same as above

 

0 Likes
Message 5 of 5

malcolm_341
Collaborator
Collaborator

Oh interesting, thanks for that clear explanation.