View Full Version : Rewriting this better and cleaner
efecto 02-19-2009, 06:52 PM This is a small simple script to select geometry. I'm wondering if anyone can help me writing it better?
Thank you.
// Select only geo
string $dmGeoShape[] = `ls -type "mesh"`;
string $dmGeos[];
for ($each in $dmGeoShape) {
string $dmGeoTr[] = `listTransforms $each`;
appendStringArray($dmGeos,$dmGeoTr,1);
}
select $dmGeos;
print (size($dmGeos) + " geos were selected!\n");
|
|
Wick3dParticle
02-19-2009, 11:11 PM
Hey Efecto...
First off, looks like you have a few undeclared vars in your script.
If I understand what you are trying to achieve correctly, then a shorter version of that would look something like this:
string $myMeshes[] = `ls -type "mesh"`;
string $myTransforms[] = `listRelatives -parent $myMeshes`;
select $myTransforms;
print (size($myTransforms) + " geos were selected!\n");
Best,
~Ilan
efecto
02-20-2009, 12:00 AM
ah I meant this
// Select only geo
string $dmGeoShape[] = `ls -type "mesh"`;
string $dmGeos[];
for ($each in $dmGeoShape) {
string $dmGeoTr[] = `listTransforms $each`;
appendStringArray($dmGeos,$dmGeoTr,1);
}
select $dmGeos;
print (size($dmGeos) + " geos were selected!\n");
that is great thank you wickedParticles.
Hey Efecto...
First off, looks like you have a few undeclared vars in your script.
If I understand what you are trying to achieve correctly, then a shorter version of that would look something like this:
string $myMeshes[] = `ls -type "mesh"`;
string $myTransforms[] = `listRelatives -parent $myMeshes`;
select $myTransforms;
print (size($myTransforms) + " geos were selected!\n");
Best,
~Ilan
efecto
02-20-2009, 12:41 AM
hi there. When trying to run wickedParticle's script I'm getting
// Error: line 3: More than one object matches name: __:name_of_GEO
r4inm4ker
02-20-2009, 01:59 AM
it means that you have non-unique short names for your nodes.
either you rename them to unique ones or query the full names:
string $myTransforms[] = `listRelatives -parent -f $myMeshes`;
efecto
02-20-2009, 02:11 AM
it means that you have non-unique short names for your nodes.
either you rename them to unique ones or query the full names:
string $myTransforms[] = `listRelatives -parent -f $myMeshes`;
Thanks both to you.
Pyrokinesis
03-21-2009, 10:38 AM
You don't need a loop. As with everything in Python or Mel, there are many ways to achieve the same result.
#Python
import maya.cmds as mc
geoShapes = mc.ls(type = "mesh")
geoTranny = mc.listRelatives(geoShapes, parent=True)
mc.select(geoTranny)
howMany = str(len(geoShapes))
print howMany + ' Geo Was selected'
Just a tip in Mel you can use:
printn "Something";
printn prints with a new line
Good Luck
CGTalk Moderation
03-21-2009, 10:38 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.
vBulletin v3.0.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.