PDA

View Full Version : Basic mel selection question


daisukem
11-19-2008, 09:01 AM
I have a scene which has nurbs and poly objects.

I would like to have a script to select only polyCube objects. Could someone help me with writing this small script for me?

// lists all the polyCube objects
string $selectPolyCube[] = `lsType polyCube`;

// select them!
???

so far my approach is to make a loop by
int $numPolyCube = size($selectPolyCube);
for ($i=0; $i<$numPolyCube;$i++)
{
//something like this
select -tgl ($selectPolyCube[$i] + "Shape");
}

I'm wondering if there is any faster way to select the objects without having to loop..

Thanks for your help.

NaughtyNathan
11-19-2008, 09:28 AM
if you have a variable array of objects, you just select the array.

string $cubes[] = `ls -type "polyCube"`;
select $cubes;

however, are you sure it's the polyCube history nodes that you want to list and select..?

I wouldn't bother with the lsType command, as it's a hacky script.. If you want to find poly objects use the ls command with the type "mesh" and for nurbs, use the type "nurbsSurface"

:nathaN

daisukem
11-19-2008, 05:17 PM
Hi Nathan thank you for your input! I tried your code.

string $cubes[] = `ls -type "polyCube"`;
select $cubes;

It did not select any cubes? Please let me know if you have any other ideas.. :(

Thank you so much.

kojala
11-19-2008, 05:56 PM
are you sure that you want to seletct polyCubes?
polyCube node exists only when creating a cube. its the one where you can set width, height
etc.
If you want the actual poly objects to be selected try this:

proc getting_stuff()
{
// getting here meshes but not the history nodes
string $meshes[] = `ls -type mesh -noIntermediate`;

// checking if any, if not, then quit
if (!size($meshes))
return;

// here getting the actual transform nodes, parents of these shape/mesh nodes
string $objects[] = `listRelatives -p $meshes`;

//then if there is any select them
if (size($objects))
select -r $objects;
}

getting_stuff()

Wick3dParticle
11-19-2008, 06:41 PM
Hey,

If you just want to select them, then just put them all in an array and select it. Like this:

string $myCubes[] = `ls -type shape "pCube*"`;

select $myCubes;


~Ilan

daisukem
11-19-2008, 06:46 PM
Thanks all. This one did the job for me. :)

Hey,

If you just want to select them, then just put them all in an array and select it. Like this:

string $myCubes[] = `ls -type shape "pCube*"`;

select $myCubes;


~Ilan

Wick3dParticle
11-19-2008, 06:50 PM
Awesome! Just remember that this relies on your naming convention. So if you were to change the name of the cubes to something like Box1,Box2, Box3...etc. then you would have to change the string in the script to "Box*". This is an example of how naming conventions are so important, and should contain a degree of consistency.

~Ilan

daisukem
11-19-2008, 09:29 PM
Ah i c ;) Thank you.

Awesome! Just remember that this relies on your naming convention. So if you were to change the name of the cubes to something like Box1,Box2, Box3...etc. then you would have to change the string in the script to "Box*". This is an example of how naming conventions are so important, and should contain a degree of consistency.

~Ilan

Norb
11-20-2008, 05:43 PM
Or yet another way of doing it :P
This will select every polygonal object in your scene regardless of naming convention..


// selects the entire scene
select -r "*";

// stores the geo in an array
string $saSel[] = `ls -sl -l -fl`;

// filters out anything that is not a polygonal object
string $saGeo[] = `filterExpand -sm 12 $saSel`;

// select the poly objects
select -r $saGeo;

Wick3dParticle
11-20-2008, 06:00 PM
Or yet another way of doing it :P
This will select every polygonal object in your scene regardless of naming convention..


// selects the entire scene
select -r "*";

// stores the geo in an array
string $saSel[] = `ls -sl -l -fl`;

// filters out anything that is not a polygonal object
string $saGeo[] = `filterExpand -sm 12 $saSel`;

// select the poly objects
select -r $saGeo;





Or I suppose you can just do that like this:

string $polys[] = `ls -type mesh`;
select $polys;


~Ilan

daisukem
11-20-2008, 06:35 PM
That is :)

Thanks all.

Or I suppose you can just do that like this:

string $polys[] = `ls -type mesh`;
select $polys;


~Ilan

jay54881984
11-21-2008, 01:44 AM
any one can tell me how to loop poly vertex in a line ( in a row or column)
I am new to mel plz help me getting out from this problem

NaughtyNathan
11-21-2008, 08:10 AM
wow, and it only took EIGHT posts to return to exactly the same thing as the original answer! :D

Wick3dParticle
11-21-2008, 02:30 PM
yup...


~Ilan

ewerybody
11-24-2008, 10:13 AM
Hello. Sorry for dropping in again after everything is "solved" already ;]
But I feel a little disturbance in the understanding of how Maya actually works:

The snipped of Nathan really DOES select the polyCube objects! These are only created if you make a cube with ConstructionHistory ON. See:
http://img141.imageshack.us/img141/2320/aashots095wz7.jpg
polyCube is a utility-node that dynamically feeds the meshShape. The transform (pCube1, yellow) is "connected" to the shape via parenting which is only visually illustrated in the outliner. But one could make a pseudo graph:



transform1

shape1(mesh)

polyCube


transform2



shape2(nurbs)

makeNurbCube


Transforms are the parents at almost every object that can be placed all over Maya.
So if you'd like to have a solid selection for all mesh/polygon objects: you better select the transform parents of the mesh-shapes!

For instance if you just select the shapes and you delete them: You really have empty transform groups flying around in your scene.

so here a little more comprehensive solution:
{
string $meshShapes[] = `ls -type "mesh"`;
string $transforms[] = `listRelatives -parent -type "transform" $meshShapes`;
select $transforms;
}

or inline without variable:
select (listRelatives("-p",`ls -typ "mesh"`));

CGTalk Moderation
11-24-2008, 10:13 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.