ConnectAttr gives error when used in loop with pairBlend shading nodes

ConnectAttr gives error when used in loop with pairBlend shading nodes

arthur_edward76
Explorer Explorer
527 Views
1 Reply
Message 1 of 2

ConnectAttr gives error when used in loop with pairBlend shading nodes

arthur_edward76
Explorer
Explorer

I'm working on a script to split a joint chain into a blended pair, for use in Fk IK system. 

I'm trying to loop through all selected joints, and for each iteration, create a pairBlend node and connect it to the related joints.

Code is:

proc EdSplitJointChain(string $splitJoints[])
{
   group -n blendChains_grp $splitJoints[0];
   
 
   
   rename $splitJoints[0] "result_root_jnt";
   group -n result_grp result_root_jnt;
   string $resultChain[] = `listRelatives -ad result_grp`;
   
   duplicate -rc result_grp;
   searchReplaceNames "result" "a" "hierarchy";
   string $aChain[] = `listRelatives -ad "a_grp*"`;
   
   duplicate -rc -n b_grp result_grp;
   select b_grp;
   searchReplaceNames "result" "b" "hierarchy";
   string $bChain[] = `listRelatives -ad "b_grp*"`;
   
    int $size = size($resultChain);
    int $i = 0;
    string $chainBlend[];
    
    for($i; $i<$size; ++$i)
    {
       $chainBlend[$i] = `shadingNode -asUtility pairBlend -n ("chainPairBlend"+$i) `;
       
       connectAttr -f ($aChain[$i]).rotate ($chainBlend[$i]).inRotate1;
       connectAttr -f ($bChain[$i]).rotate ($chainBlend[$i]).inRotate2;
       connectAttr -f ($chainBlend[$i]).outRotate ($resultChain[$i]).rotate;
    }
   
}



where $splitJoints[] is the original chain to be split. 
I have problems in the loop section. No matter what I do, I get an error with the name of the shading node: "Invalid object or value: chainPairBlend0"
I've tried changing the order, using a blendColors instead, and still I get the error. I'm mirroring the exact syntax that gets shown in the script history when I do it by hand, I'm just substituting the names with the positions in the $chainBlend[] array.

I know the script is very messy - I'm not good at coding, so any advice is appreciated.
Thanks very much for your help.

0 Likes
528 Views
1 Reply
Reply (1)
Message 2 of 2

kollig
Advocate
Advocate

I think, it has to be

 

connectAttr -f ($aChain[$i]+".rotate") ($chainBlend[$i]+".inRotate1");

and so on.

 

-Thomas

0 Likes