Selecting all polygon objects in the scene with a certain prefix?

Selecting all polygon objects in the scene with a certain prefix?

Anonymous
Not applicable
3,443 Views
4 Replies
Message 1 of 5

Selecting all polygon objects in the scene with a certain prefix?

Anonymous
Not applicable
Hi guys,

Hope you're all well.

So i'm relatively new to mel and have managed just fine so far copying and editing other peoples scripts and writing my own (basic ones 😉 Now i'm stuck and could really do with all your help.

I've spent a week building a scene filled with hundreds and hundreds of doors that open and close randomly. All these doors have hinges that are just to big. i want to make them smaller. Now there are thousands. SO

I want to write a script that looks through all the nodes in the scene and selects all the polygon meshes that have steelHinge in the name (all the hinges are steelHinge01, steelHinge02 and so on. The number at the end is quite random as ive deleted some and added some during the week. Nonetheless they all have a certain prefix

This is what i have at the moment, but i dont see anything selected in my viewport, and also it seems to be missing some???


// declare an array called $nodes. Call ls to list
// the nodes in the scene
$meshes = `ls -type "mesh"`;

// loop through each mesh
for( $mesh in $meshes )
{
// print the mesh name

$name = $mesh +"\n";

if(startsWith($name, "steelHinge"))
{
print($name);
}
}
0 Likes
3,444 Views
4 Replies
Replies (4)
Message 2 of 5

lee.dunham
Collaborator
Collaborator
replied on cgSociety: http://forums.cgsociety.org/showthread.php?p=7274246#post7274246

your not finding anythings selecting because your not telling maya to select anything.
btw the script works, but it will only return you the shape node (not the transform node that you'll want to scale)
Try this;
// loop through each mesh
string $nodes[] = `ls -type "mesh"` ;
select -d ;
for($mesh in $nodes)
if(startsWith($mesh, "steelHinge"))
select -tgl `listRelatives -p $mesh` ;


however if your interested, I would suggest using python, especially for operations like this, as you can use its list comprehension abilities to condense the above script to 1 line (minus the importing of the module) as its far more flexible with string operations.
import maya.cmds as mc
mc.select( == 'steelHinge'],r=1)
0 Likes
Message 3 of 5

Anonymous
Not applicable
Found out how thanks to some legend at simplymaya who simplified it down to this:

umm... use select by name and type steelHinge*
0 Likes
Message 4 of 5

Anonymous
Not applicable
I would suggest using python, especially for operations like this, as you can use its list comprehension abilities to condense the above script to 1 line (minus the importing of the module) as its far more flexible with string operations.
import maya.cmds as mc
mc.select( == 'steelHinge'],r=1)

Error. It's not selecting anything:
// Error: Line 2.11: Syntax error //
0 Likes
Message 5 of 5

lee.dunham
Collaborator
Collaborator
are you executing it as mel? That'll probably be your error as its a python script.

btw I completely overlooked the simplified `ls "*steelHinge*"`
0 Likes