Derive default maya shelves

Is there a command that specifically gets the default maya shelves?
By default shelves, I mean as follows:

'Poly Modeling',
'Sculpting',
'Rigging',
'Animation'

I am trying to find a way to differentiate the ones I created (user shelves) apart from the default ones

short demonstration:

maya_window_name = mel.eval('$tmpVar = $gMainWindow;')
shelf_top_level = mel.eval('global string $gShelfTopLevel; $temp = $gShelfTopLevel;')
all_shelfs_tabs_names = cmds.tabLayout(shelf_top_level, query = True, childArray = True)
shelf_tab_name = cmds.tabLayout(shelf_top_level, query = True, selectTab = True)
current_shelf = '{}|{}'.format(shelf_top_level, shelf_tab_name)

buton_name = 'Reload All Textures in Viewport'

cmds.shelfButton(enableCommandRepeat = True,
                          annotation = buton_name,
                               label = buton_name,
                   imageOverlayLabel = 'Reload\nTexture',
                             command = 'cmds.ogs(reloadTextures = True)',
                          sourceType = 'python',
                   flexibleWidthType = 3,
                  flexibleWidthValue = 32,
                              enable = 1,
                               width = 35,
                              height = 34,
                              manage = 1,
                             visible = 1,
                     preventOverride = 0,
                    enableBackground = 0,
                     backgroundColor = (0.0, 0.0, 0.0),
                      highlightColor = (0.321569, 0.521569, 0.65098),
                               align = 'center',
                         labelOffset = 0,
                            rotation = 0,
                               flipX = 0,
                               flipY = 0,
                            useAlpha = 1,
                                font = 'plainLabelFont',
                   overlayLabelColor = (0.0, 1.0, 1.0),
               overlayLabelBackColor = (0.0, 0.0, 0.0, 0.5),
                               image = 'commandButton.png',
                              image1 = 'commandButton.png',
                               style = 'textOnly',
                         marginWidth = 1,
                        marginHeight = 1,
                   commandRepeatable = 1,
                                flat = 1,
                              parent = current_shelf)

print (('\t Creating Button \"{}\" on shelf: \"{}\" - complete.\n'
       ).format(buton_name,  shelf_tab_name))


separator = cmds.separator(parent = current_shelf,
                           enable = 1,
                            width = 12,
                           height = 35,
                           manage = 1,
                          visible = 1,
                  preventOverride = 0,
                 enableBackground = 0,
                  backgroundColor = (0, 0, 0),
                   highlightColor = (0.32, 0.52, 0.65),
                            style = 'shelf',
                       horizontal = 0)

print('\n\t Creating Separator on shelf: \"{}\" - complete.\n'.format(shelf_tab_name))
cmds.saveAllShelves(shelf_top_level)

tabLayout command (Python):

I know I’m a year too late, but I just prefix mine with my handle. So: dag_shelfname

You can of course make a list as you have and type in all shelves manually to compare to. Sure, it might change through Maya versions so it’s probably not the best solution.

Just thought I’d update what I found.
I poked around some because I was curious.
In initShelf.mel there’s global proc createDefaultShelves() which creates the shelves, but the shelves names are just written in that file and are added to an optionVar, which you can retrieve like this:

nShelves = mc.optionVar( q="numShelves")
for i in range(nShelves):
    print(mc.optionVar( category="Shelves", q='shelfFile'+str(i+1)))

However, this option variable holds all the shelves in the shelf layout so it doesn’t help…

You could go a few ways.

  1. Either append a prefix to all your custom shelves so that you can easily filter those

  2. or you could get all of Maya’s native shelves from here:
    C:\Program Files\Autodesk\Maya2027\scripts\shelves
    and filter on those. But then what do you do when you need to filter out plug-ins shelves?

My advice:
Write a script to read the names of all the shelves from the install dir.
Then prefix all your custom shelves with a unique signature.
Now you can find out just which shelf is your own, a plug-in’s or Maya’s native.

1 Like