View Full Version : MEL script to output all attribute values to a .txt file?
12 December 2010, 07:08 PM
Ok, forgive me if this is already posted as I am extremely new to the world of MEL scripting. I did several searches on this, and it's possible that due to my lack of knowledge on MEL language terminology that I was unable to find anything about this topic.
So I am currently testing an underwater lighting setup, and received some help along the way. I wanted to be able to output all values of attributes in use, into an easily viewable text or word file to send to the individual that assisted me early on. I realize that I could just click on every tab and type them out but I thought it would be nice to write a script that would do this for me.
My shader network is rather complex has several nodes and it would be nice to have somewhat of a master sheet to refer back to, as well as to pass along to others. If anyone has any suggestions or can tell me how to do this I would be extremely appreciative!
I have read up on getAttr:, and listAttr, I was able to list the attributes however not the values associated with them.
Thanks in advance!
12 December 2010, 10:07 PM
You can do it, but it is a bit more complex. If you are new to mel, I suggest to use python instead of mel. But for both you need some deeper knowledge of maya and python/mel, especially if you want to parse a shading network.
12 December 2010, 04:51 AM
Thanks for your response and I have a firm grasp on the software, however the language that drives it is new. I won't ask you to explain it, however would you mind giving me some keywords that might help me find refrence through the forum or google? Also I don't 100% need it to write to a text file, copy and pasting from the script editor works if that simplifies things.
12 December 2010, 08:25 AM
Question here is what attributes you really want to output to text file.
Do you want to put for example all attributes on blinn node etc.
What you mean when you say atrributes in use?
You can for example query attributes that are connected , maybe attributes that are not at "default" value.
Maybe solution work you would be to make some "master" node , and make attributes here , and make connections to all nodes in network , or maybe to make you custom gui for same purpose.
If you are new to mel/python , making something usable here is not that easy btw.
12 December 2010, 03:23 PM
I have read up on getAttr:, and listAttr, I was able to list the attributes however not the values associated with them.You'll have to get the object(s), attributes and values separately. Here's an example:
//Define the object
string $object = "pCube1";
//Get the attributes of pCube1
$attributes = `listAttr -keyable pCube1`;Ok, so now all of the keyable attributes of pCube1 are stored within the variable $attributes. As there's more than one attribute, $attributes will be an array, which means that all of the attributes are stored separately within the variable. $attributes contains the first attribute, $attributes contains the second, and so on.
To get the value of an attribute (getAttr), you also need to include the name of the object (pCube1.attribute). So if I want to get the value of the secondth attribute of $attributes, I can do this:
//Get the value of the secondth item in $attributes
$val = `getAttr ($object + "." + $attributes)`;The reason why I use "." is that the dot isn't stored in any of the variables.
Now we have the object, the attribute and the value of the attribute in three separate variables, all we need to do now is to print them all in one string:
//Print the object, the secondth attribute, and it's value
print ($object + "." + $attributes + " = " + $val);
Here's another example, this script prints each keyable attribute of all of the selected objects:
//Get the selected objects
$selObj = `ls -sl`;
//For each selected object
for($sel in $selObj)
//Get all keyable attributes of the current object
$attributes = `listAttr -keyable $sel`;
//For each keyable attribute of the current object
for($attr in $attributes)
//Get the value of the current attribute
$val = `getAttr ($sel + "." + $attr)`;
//Print the value of the attribute (object.attribute = val)
print ($sel + "." + $attr + " = " + $val + "\n");
12 December 2010, 10:11 PM
Exactly what I needed! Thank you for all your help,it is very much appreciated.
12 December 2010, 10:11 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.