PDA

View Full Version : Variables in attribute names


DeadlyNightshade
11-21-2012, 03:45 PM
I'm trying to do some simple connect/disconnects in the connection editor automated.

disconnectAttr file5732.outTransparency plates.transparency;
That's the command

// AIDSCODE

// Select material
$matName = `ls -sl -mat`;

// Find file node name
string $connections[] = `listConnections`;
int $connectionsSize = `size($connections)`;
int $number = $connectionsSize - 1;
string $fileName = $connections[$number];

print $fileName;
print ("\n");
print $matName;

// prints says $fileName is file5732 and material name is plates

// Operations
disconnectAttr $fileName.outTransparency $matName.transparency;

And the above is my code. Don't mind my sloppy way of finding the file name - in this particular case every material have just one file node and it's always at the end of listconnections so yea...

The thing is that the operation at the bottom does not work and I can't understand why. I added some prints to confirm that I got the file and material names correct so it's not that.

The error I get:
// Error: line 17: Invalid object or value: plates //

nookie
11-21-2012, 03:53 PM
As far as I remember you cannot concatenate stuff like that in mel.
I have no maya here but it should be something like this

disconnectAttr ($fileName + ".outTransparency") ($matName + ".transparency");

DeadlyNightshade
11-21-2012, 04:00 PM
// Error: Line 17.77: Illegal operation "+" on data of type string[]. //

I've aso tried:
disconnectAttr `$fileName.outTransparency` `$matName + .transparency`;

and...

disconnectAttr `$fileName.outTransparency $matName + .transparency`;

nookie
11-21-2012, 04:26 PM
try $filename[0] or matName[0].
Seems that at least one of those variables is an array

rgkovach123
11-21-2012, 04:55 PM
You need to join the value of the attribute with a string first. If a variable is a string array, then you need to retrieve a specific index. the ls command always returns an array, even with 1 object selected.

like nookie said:



connectAttr ($filenode + ".outTransparency")
($matName[0] + ".transparency");



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

I've aso tried:
disconnectAttr `$fileName.outTransparency` `$matName + .transparency`;

and...

disconnectAttr `$fileName.outTransparency $matName + .transparency`;

CGTalk Moderation
11-21-2012, 04:55 PM
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.