Easier way to group sets of objects using MEL

Easier way to group sets of objects using MEL

Anonymous
Not applicable
550 Views
2 Replies
Message 1 of 3

Easier way to group sets of objects using MEL

Anonymous
Not applicable

New to MEL but I have a script that's generating 400 cubes named polyCube1 - polyCube400. I need to split them into groups every 20 cubes (so first group has polyCube1 - polyCube20 next group polyCube21 - polyCube 40 etc.) but so far the only way I've figured out how to do this is my selecting each individual cube from 1-20 with the select command then grouping them rinse repeat for all 400. Is there a better way to do this using some sort of loop?

0 Likes
551 Views
2 Replies
Replies (2)
Message 2 of 3

haggi_master
Advocate
Advocate

I know you'd like to use mel, but I recommend using python especially if you are starting with scripting. With python it would look like this:

import pymel.core as pm

group = None
for i in range(40):
    index = i/20
    groupName = "Group{0}_{1}".format(index * 20 + 1, (index + 1) * 20)
    if not pm.objExists(groupName):
        group = pm.group(em=True, name=groupName)
    pc = pm.polyCube()[0]
    pm.parent(pc, group)
Message 3 of 3

rajasekaransurjen
Collaborator
Collaborator

Hi,

Try this....

Select Cube 1 to 400 then run the script.

string $rsSl[];
$rsSl=`ls -sl`;
select -cl;
for($i=1;$i<=size($rsSl);$i++)
{
    select -tgl ("pCube"+$i);
    if(($i%20)==0)
    {
        group;
        select -cl;
    }
} 
0 Likes