conecting Attribute between two groups

conecting Attribute between two groups

giorgiodaulerio
Explorer Explorer
532 Views
3 Replies
Message 1 of 4

conecting Attribute between two groups

giorgiodaulerio
Explorer
Explorer

Hi,

I'm tring to connect attribute between two groups of object,

but when I write this:

 

connectAttr ($objectsInGroup1 + ".rotateX") ($objectsInGroup2 + ".rotateX");
connectAttr ($objectsInGroup1 + ".rotateY") ($objectsInGroup2+ ".rotateY");
connectAttr ($objectsInGroup1 + ".rotateZ") ($objectsInGroup2 + ".rotateZ");


Maya give me this error:

// Error: Line 3.39: Illegal operation "+" on data of type string[]

Can Someone help me?

 

0 Likes
533 Views
3 Replies
Replies (3)
Message 2 of 4

FirespriteNate
Advocate
Advocate

The error suggests that either $objectsInGroup1 or $objectsInGroup2 is an array, and not a single string. You cannot join an array (a list of items) to a single item, which is what it seems you are doing when you specify:

 

$objectsInGroup1 + ".rotateX"

 

Looking at your example code, it seems like you are trying to connect an attribute on multiple objects at once. This is impossible, you must iterate over the items in an array and set or connect the attribute individually on only one item at a time, something like this example:

 

for ($item in $objectGroup)
{
    // do somthing to $item
}

 

In your example case, it seems you want to connect an attr from a single item in an array to another single item in another array 🤔

 

This is starting to become complicated by things like, what if there is a different number of items in one array than the other?

 

But, assuming both $objectsInGroup1 and $objectsInGroup2 are arrays with the same number of items, and you want to connect the 1st item in one with the 1st item in the other, then the 2nd in the first to the 2nd in the other, etc... you could do something like this:

 

int $count = `size $objectsInGroup1`;
for ($i=0; $i<$count; $i++)
{
    connectAttr ($objectsInGroup1[$i]+".rotateX") ($objectsInGroup2[$i]+".rotateX");
    connectAttr ($objectsInGroup1[$i]+".rotateY") ($objectsInGroup2[$i]+".rotateY");
    connectAttr ($objectsInGroup1[$i]+".rotateZ") ($objectsInGroup2[$i]+".rotateZ");
}

 

 

I'm assuming though, that you are aware that $objectsInGroup1 and $objectsInGroup2 are arrays and what that involves...

Message 3 of 4

FirespriteNate
Advocate
Advocate

re-reading your original post it seems possible that your issue is that $objectsInGroup1 and $objectsInGroup2 are NOT supposed to be arrays, and this is the problem. If these are just supposed to be the single string name of two groups and not an array of items as I first thought, then your issue is probably just that you captureds that name using the ls command, and this always returns an array, for example:

string $selectedThings[] = `ls -sl`;
// $selectedThings is now an array!
string $myGroup1 = $selectedThings[0];
// now $myGroup1 is a single string, the first element in the $selectedThings array
0 Likes
Message 4 of 4

giorgiodaulerio
Explorer
Explorer

Thank you very much for your reply and sorry if I was unclear in my post.

Yes, I wanted try to connect 2 object's groups,  and finally whit your help seems it works, i wrote this:

 

string $A[] = `ls -sl("*_ctrl")`;

string $B[] = `ls -sl("BS_*_ctrl")`;

int $count = `size $A`;

for ($i=0; $i<$count; $i++)
{
connectAttr ($A[$i]+ ".translateX") ($B[$i] + ".translateX");
connectAttr ($A[$i]+ ".translateY") ($B[$i] + ".translateY");
connectAttr ($A[$i]+ ".translateZ") ($B[$i] + ".translateZ");


}

 

It seems work, every attribute is connected, but at the end came out this error:

// Error: line 9: 'BS_pSphere1_ctrl.translateX' already has an incoming connection from 'pSphere1_ctrl.translateX'.

0 Likes