PDA

View Full Version : Connecting Object Pairs (For loops)


ColinKennedy
11-23-2011, 12:16 AM
I have a situation where I have a bunch of projection nodes - let's call them projection. And they start with projection, projection1, projection2, projection 3, and so on.
I'm trying to build a for loop that will connect projection.outColor to a plusMinus utility node's input[0], projection1 to input[1], projection 2 to input[2] and so on.
So basically I'm pairing each number of the projection to the same number in the plusMinus.

So far, what I wrote works perfectly, I get the result I need. But for some reason the script doesn't stop at the point where it connects everything. I get an error saying that a connection could not be made to plusMinus.outColor. Obviously, the reason it's coming up with this error is because that node doesn't have an outColor attribute. Here is the code:



// Assume that a plusMinusAverage node named plusMinus_ut and a bunch of projection nodes have been created
string $connectProjToUt[]=`ls "projection*"`;
int $a;
for($a=0; $a<size($connectProjToUt); ++$a) {
connectAttr ($connectProjToUt[$a] +".outColor") plusMinus_ut.input3D[$a];
}




For the heck of it, I gave the plusMinus an outColor attribute and it looks like the script is trying to find and then connect a nonexistent plusMinus_ut.outColor back into plusMinus_ut.input3D. This is not only impossible but it would undo the original connections between the projections so it's important that I solve this error. I don't know why the script is assuming the plusMinus has an outColor at all but I only just learned of wild cards the other day so maybe that is the problem.

I tried experimenting with the -na flag for connectAttr to no avail. Maybe someone has some info on that?

depakeen
11-23-2011, 03:10 PM
Really basic (sorry if you've already done that, but sometimes I don't think about the easiest things myself. I guess - I hope ;) - I'm not the only one), but did you try to print your stringArray $connectProjToUt[] to see if you have only what you need?
Maybe you should use the -type flag in your ls command to specify what you need?
I'm not a good Mel coder at all, sorry if it doesn't help...

ColinKennedy
12-03-2011, 07:02 AM
Sorry for being late on the reply. Turns out printing the array was just what I needed. I misunderstood the purpose of the wild card. I thought that the wild card only functioned with numbers with a padding but it was also picking up "_" and "-" suffixes as well. I just had to rename a couple files and the script is now completely fixed.

I always feel bad asking questions like these on CgTalk because I overthink the simple solutions like this. But thank you very much for the response, I'll keep that trick in mind in the future when troubleshooting!

CGTalk Moderation
12-03-2011, 07:02 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.