1

I'm trying to alphabetically order Maya shelves. I know that I can import shelves in order but I want to do this after the shelves are imported as the default Maya shelves are automatically imported into Maya.

I tried using the position argument in the shelfLayout command but I'm not sure if it's the right one or if it is, then I don't know how to use it. If someone could shed some light on this, it would be amazing.

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Rocker
  • 11
  • 1

1 Answers1

0

Look at the following code snippet to find out how to reorder Shelf Tabs alphabetically:

import maya.cmds as cmds
import maya.mel as mel

def reorderTabsAlphabetically():

    gshelf = mel.eval("$temp = $gShelfTopLevel")
    shelves = cmds.tabLayout(gshelf, q=1, childArray=1)

    total = len(shelves)   
    pref = 'abc' 
    print(total)                                                   # 16 tabs

    shelf = sorted([s for s in shelves if s.startswith(pref)]) +   # line break
            sorted([s for s in shelves if not s.startswith(pref)])

    for i, object in enumerate(shelf):
        i += 1
        sIndex = cmds.tabLayout(gshelf, q=1, childArray=1).index(object) + 1
        cmds.tabLayout(gshelf, e=1, moveTab=(sIndex, i))

reorderTabsAlphabetically()

enter image description here

As you can see all the tabs are now arranged in the ascending order (alphabetically).

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220