[Maya MEL] Creating Offset Group: For Loop Error



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:

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];



Hi @Theodox

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