Help: MEL/Python Group every 3 groups?


#1

Hey guys,

I have a project I am working on and I desperately need a script to finish it.

I used xgen to populate a bunch of trees in my scene. I exported them to polygons. Now in Maya, the groups in the outliner look like this:

xgPrim76_0_ForestTrees_Mid
xgPrim76_1_ForestTrees_Mid
xgPrim76_2_ForestTrees_Mid
xgPrim77_0_ForestTrees_Mid
xgPrim77_1_ForestTrees_Mid
xgPrim77_2_ForestTrees_Mid

All the way down to xgPrim900 and something. I need to group every 3 and rename them with a different name.

Any ideas in how to do this? I know some Python and MEL but I’ve never done this before.

Thank you!


#2

At least the grouping thing could be solved with:

import pymel.core as pm
for tr in pm.ls("xgPrim*", type = "transform"):
    key = tr.split("_")[0]
    if not pm.objExists(key):
        pm.group(em=True, name=key)
    pm.parent(tr, key)

It groups every three elements under a common name.


#3

Thanks for that! I’ll test it out. :slight_smile: