[Maya MEL] Creating Offset Group: For Loop Error

Hi,

I wanted to create a script that creates offset groups. It works on the single objects but not on multiple objects (which is the intended use).

You can see an illustration of the problem here:
https://www.dropbox.com/s/z7m768d2yneka3n/MYA071_offset_group_error.mp4?dl=0

You can check the script here:

$objList = `ls -sl`;

for ($obj in $objList){
    
    $objParent = `pickWalk -d up`; 
    $objGrp = `group -em -n ($obj + "_grp")`;
    parent $objGrp $obj;
    setAttr ($objGrp + ".tx") 0;
    setAttr ($objGrp + ".ty") 0;
    setAttr ($objGrp + ".tz") 0;
    setAttr ($objGrp + ".rx") 0;
    setAttr ($objGrp + ".ry") 0;
    setAttr ($objGrp + ".rz") 0;
    setAttr ($objGrp + ".sx") 1;
    setAttr ($objGrp + ".sy") 1;
    setAttr ($objGrp + ".sz") 1;
    parent -w $objGrp;
    
    parent $objGrp $objParent;
    parent $obj $objGrp;
}

Thank you for looking at the problem

You’re using pickwalk, which is relative to the selection. Maybe you want something like:

string $p[] = `listRelatives -p $obj`;
string $objParent  = $p[0];

instead?

2 Likes

Hi @Theodox

Works as expected! I initially thought listRelatives was only for children. It turns out it also works for parents. Thanks again!