View Full Version : outputting CV attribute to file

12 December 2003, 04:23 AM
im trying to output x y z attributes of a shape's CVs to a file...

Heres my script:
string $sName = `file -q -sceneName`;
$fileId = fopen($sName + ".txt","w");
fprint($fileId, $sName);
int $i;
int $j;

for($i = 0; $i < 7; $i++) {
for($j = 0; $j < 8; $j++){
print($i+" " + $j + "\n");
float $cvInf[] = getAttr("[$i][$j]");
string $cv0 = $cvInf[0];
string $cv1 = $cvInf[1];
string $cv2 = $cvInf[2];
fprint($fileId, $cv0 + $cv1 + $cv2 + "\n");


And this is the error I get:
// Error: Invalid attribute index:[$i][$j] //
But if I just put integers instead of i and j, it works.
I dont understand. :( Thanks

12 December 2003, 03:15 PM
Your variables are inside your string(given by ""), so instead of evaluating the real value of the variable (which is what you want), it evaluates a string that actually has the $ character in it.

Just build your string and leave the $ outside the "":

getAttr("[" + $i + "][" + $j + "]");

12 December 2003, 05:06 PM
thanks! that makes sense (and it worked ;) -
why does getAttr take a string as a argument anyway?
That seemed funny to me.

12 December 2003, 03:17 PM
why does getAttr take a string as a argument anyway?

Any name in MEL is considered a string- node name, attr name, UI control name, file name - these are all strings.

CGTalk Moderation
01 January 2006, 11:00 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.