PDA

View Full Version : Selecting Multiple Objects by Name


ColinKennedy
11-17-2011, 05:00 AM
It seems like it'd be a simple solution but I'm new to MEL so I wouldn't know exactly how/where to search for this solution. Please direct me if there are forums that I overlooked.

I have a script that makes a bunch of file nodes - whose name I define always starting with the number 1. I also define the end number. So name1 name2 name3 - if I called the files" name" and asked for three of them - and so on.

I need to select all of these name files at once so that I can use a for loop to connect each of the object's outColor to a plusMinusAverage's input3D node. I understand the concept of the for loop for doing that but most tutorials I've found assume that you have something selected in a string. In my case, I have nothing selected and need to select all of these files by name and differing numbers alone. How might I do this?

WesHowe
11-17-2011, 05:30 AM
You want the 'ls' command with wildcards. This line should do it:
string $myItems[]=`ls "name*"`;

$myItems is an array of strings, so using it in a loop would go like this:
int $i;
for($i=0; $i<size($myItems); ++$i) {
print("found "+$myItems[$i]+"\n");
}

<* Wes *>

ColinKennedy
11-17-2011, 05:36 AM
Thank you very much for the fast reply. Your solution worked perfectly!

CGTalk Moderation
11-17-2011, 05:36 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.