Search code examples
mayamel

Maya MEL save listAttr into array


Cheers, I am writing on a tool that should get all attributes with a specific prefix and save them into an array.

When I use the listAttr on its own it gives me something like this: // Result: message caching isHistoricallyInteresting nodeState...

My problem: I want to save the list of the Attribute with a specific prefix into an array

mel code:

string $currentSelection[] = `ls -sl`;
string $currentAttributes[];            
$currentShapeNode = `ls -shapes -dag -sl $currentSelection`;
string $currentAttributes[] = `listAttr -ct "ai*"`;
print $currentAttributes;

The $currentAttributeslist stays empty. I can´t figure out what I am doing wrong.


Solution

  • You probably confused with category and string. If you take a look close in doc

    ct -> only show attributes belonging to the given category. Category string can be a regular expression.

    st -> List only the attributes that match the other criteria AND match the string(s) passed from this flag. String can be a regular expression.

    So in your case you probably looking for st

    This works

    string $currentSelection[] = `ls -sl`;
    string $currentAttributes[];            
    $currentShapeNode = `ls -shapes -dag -sl $currentSelection`;
    string $currentAttributes[] = `listAttr -st "ai*"`;
    print $currentAttributes;