FORUMS: list search recent posts

MEL Array and fprint issues

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Adam Benson
MEL Array and fprint issues
on Mar 24, 2013 at 7:02:45 pm

Hey All,
I'm trying to write a tool, and I'm running into an issue with fprint writing the object name to the text file. All the light attributes work just fine, but the light name... not so much. Basically, this is what I'm doing:

//Start the script
string $openThisFile;
string $getFileName = `file -q -sn -shn`;
string $compileName = basename($getFileName, ".mb");
string $AllLights[] = `ls -lights -long`;
float $thisRx;
float $thisRy;
float $thisRz;
vector $thisColor;
float $thisIntensity;
select -r $AllLights;
$openThisFile = ($compileName + "_LightRig_v01.txt");
$exampleFileName = ( `internalVar -userScriptDir` + $openThisFile );
$fileId=`fopen $exampleFileName "w"`;
fprint $fileId ($getFileName + "n");
for ($thisLight in $AllLights){
$getLightSettings = `listRelatives -parent $thisLight`;
select -r $getLightSettings;
$thisRx = `getAttr $getLightSettings.rx`;
$thisRy = `getAttr $getLightSettings.ry`;
$thisRz = `getAttr $getLightSettings.rz`;
$thisColor = `getAttr $getLightSettings.color`;
$thisIntensity = `getAttr $getLightSettings.intensity`;
fprint $fileId ($getLightSettings + "n");
fprint $fileId ($thisRx + "n");
fprint $fileId ($thisRy + "n");
fprint $fileId ($thisRz + "n");
fprint $fileId ($thisColor + "n");
fprint $fileId ($thisIntensity + "nn");
}
fclose $fileId;
// End the script

Everything works great, except... whenever I try to include the object name, the name of the light, it craps out on me, and says it can't convert the type $string[] to string. What am I missing?
I need this to collect all of the light basic information:
Light name - currently failing.
Light Rotation - works fine.
Light color - works fine.
Light intensity - works fine.
Write it all to a text file - works fine until I try to add the light name.
Any help would be appreciated!
Thanks much,
Adam

Adam Benson
Visual Effects Artist
http://www.SleepDeprivedProductions.com
http://www.SleepDeprivedFilms.com


Return to posts index

Steve Sayer
Re: MEL Array and fprint issues
on Mar 25, 2013 at 6:33:02 pm

Hi, Adam.

I think the problem is that when you use the listRelatives command to get the name of the light's transform node, that name gets stored as an array by default.

This is a pretty common behaviour in Maya: any command that could sometimes return an array of values will always return an array, even when it's just returning a single item. We humans tend to assume that if there's only one item in a response, it should be a regular string, not a single-item string array... but that's not how it works in Maya's 'mind'.

Try fprinting "$getLightSettings[0]" and your script will probably work.


Return to posts index

Adam Benson
Re: MEL Array and fprint issues
on Apr 21, 2013 at 1:47:37 am

Thanks for the help, Steve! That did it!

Adam Benson
Visual Effects Artist
http://www.SleepDeprivedProductions.com
http://www.SleepDeprivedFilms.com


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]