<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to list custom attribute short names? in Maya Programming Forum</title>
    <link>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11728653#M1364</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11712848"&gt;@Kahylan&lt;/a&gt;thanks for your help, I can kind of read the Python, but not really, it did lead me to a solution though. Maybe this can be written in less lines, but it seems to do the trick.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    //Get mesh name
    string $meshName[] = `ls -sl`;

    //Get long attribute names
    string $attrLongName[] = `listAttr -userDefined $meshName[0]`;

    //Set up arrays and counters
    int $counter = 0;
    string $attrNiceName[] = {};
    string $tempArray[] = {};
    
    //Loop to get nice names    
    for ($item in $attrLongName)
    {
        //Get nice name
        string $tempString = `attributeQuery -node $meshName[0] -niceName $attrLongName[$counter]`;
        //Convert string to string array
    	$tempArray = stringToStringArray($tempString, " ");
    	//Append to array
        appendStringArray($attrNiceName, $tempArray, 1);
        $counter = $counter + 1;
        
        //Print contents
        print $attrNiceName;
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Feb 2023 21:42:12 GMT</pubDate>
    <dc:creator>malcolm_341</dc:creator>
    <dc:date>2023-02-03T21:42:12Z</dc:date>
    <item>
      <title>How to list custom attribute short names?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11725946#M1360</link>
      <description>&lt;P&gt;Hi, from the Maya help file it says I can list the short names of custom attributes on a mesh using this command listAttr -userDefined -shortNames&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I use that command it always returns the long names, is this a bug, or is there a trick or something to get it to work?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 23:16:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11725946#M1360</guid>
      <dc:creator>malcolm_341</dc:creator>
      <dc:date>2023-02-02T23:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to list custom attribute short names?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11726349#M1361</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How did you create the attribute?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The thing is that there are 3 types of attribute names in Maya. Longnames (Name Stored in the Node), Nicenames (Name displayed in channelbox and Attribute Editor) and short names (Name that can be used to address the attribute via code).&lt;/P&gt;&lt;P&gt;Long and nice name can be set through the UI, shortnames can only be set using the addAttr command using the -sn flag.&lt;/P&gt;&lt;P&gt;Could it be that you are confusing Nicename and Shortname? because I could not reproduce this issue. If I set the shortname using the addAttr command, maya (2022.4) will reliably return it when I use the listAttr command.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it helps!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 04:00:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11726349#M1361</guid>
      <dc:creator>Kahylan</dc:creator>
      <dc:date>2023-02-03T04:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to list custom attribute short names?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11726384#M1362</link>
      <description>&lt;P&gt;It's entirely possible I'm confused this is the first time I've worked with extra attributes. A person gave me a scene with the attributes already added and I'm trying to query the nice name I guess which I had thought was the short name. Is there a way to query the nice names for the extra attributes of a mesh and store them in an array similar to&lt;/P&gt;&lt;P&gt;listAttr -userDefined $meshName[0];&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 04:41:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11726384#M1362</guid>
      <dc:creator>malcolm_341</dc:creator>
      <dc:date>2023-02-03T04:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to list custom attribute short names?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11726878#M1363</link>
      <description>&lt;P&gt;You can use listAttr to get the userdefined attributes and then loop through them using attributeName.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sadly I'm in a bit of a hurry today, so I only had time to write this in python. But I know you are good enough in MEL to convert this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import maya.cmds as mc

sl = mc.ls(sl=True)[0]

attrs = mc.listAttr(sl,ud= True)

niceNameList = []
for a in attrs:
    nn = mc.attributeName("{0}.{1}".format(sl, a), n= True)
    niceNameList.append(nn)
    
print(niceNameList)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it helps!&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 09:44:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11726878#M1363</guid>
      <dc:creator>Kahylan</dc:creator>
      <dc:date>2023-02-03T09:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to list custom attribute short names?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11728653#M1364</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11712848"&gt;@Kahylan&lt;/a&gt;thanks for your help, I can kind of read the Python, but not really, it did lead me to a solution though. Maybe this can be written in less lines, but it seems to do the trick.&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    //Get mesh name
    string $meshName[] = `ls -sl`;

    //Get long attribute names
    string $attrLongName[] = `listAttr -userDefined $meshName[0]`;

    //Set up arrays and counters
    int $counter = 0;
    string $attrNiceName[] = {};
    string $tempArray[] = {};
    
    //Loop to get nice names    
    for ($item in $attrLongName)
    {
        //Get nice name
        string $tempString = `attributeQuery -node $meshName[0] -niceName $attrLongName[$counter]`;
        //Convert string to string array
    	$tempArray = stringToStringArray($tempString, " ");
    	//Append to array
        appendStringArray($attrNiceName, $tempArray, 1);
        $counter = $counter + 1;
        
        //Print contents
        print $attrNiceName;
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 21:42:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11728653#M1364</guid>
      <dc:creator>malcolm_341</dc:creator>
      <dc:date>2023-02-03T21:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to list custom attribute short names?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11729806#M1365</link>
      <description>&lt;P&gt;Adding new items to an array is a bit cluncky in MEL.&lt;/P&gt;&lt;P&gt;This way is a bit more efficient:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    //Get mesh name
    string $meshName[] = `ls -sl`;

    //Get long attribute names
    string $attrLongName[] = `listAttr -userDefined $meshName[0]`;

    //Set up arrays and counters
    string $attrNiceName[] = {};
    
    //Loop to get nice names    
    for ($item in $attrLongName)
    {
        string $niceName = `attributeName -n ($meshName[0] +"."+ $item)`;
    	//Append to array
        $attrNiceName[size($attrNiceName)] = $niceName;
        
        //Print contents
        print $attrNiceName;}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also if you want to allow multi-selection it would look like this:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;    //Get mesh name
    string $meshNames[] = `ls -sl`;
    string $attrNiceName[] = {};
    
    for ($mesh in $meshNames){
        
            //Get long attribute names
            string $attrLongName[] = `listAttr -userDefined $mesh`;
        
            //Set up arrays and counters
        
            
            //Loop to get nice names    
            for ($item in $attrLongName)
            {
                string $niceName = `attributeName -n ($mesh +"."+ $item)`;
            	//Append to array
                $attrNiceName[size($attrNiceName)] = $niceName;
                
                //Print contents
                print $attrNiceName;}
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it helps!&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 14:43:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11729806#M1365</guid>
      <dc:creator>Kahylan</dc:creator>
      <dc:date>2023-02-04T14:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to list custom attribute short names?</title>
      <link>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11730069#M1366</link>
      <description>&lt;P&gt;Oh cool thanks for the optimization and the original help.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Feb 2023 18:00:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/maya-programming-forum/how-to-list-custom-attribute-short-names/m-p/11730069#M1366</guid>
      <dc:creator>malcolm_341</dc:creator>
      <dc:date>2023-02-04T18:00:45Z</dc:date>
    </item>
  </channel>
</rss>

