Maya 2022 Python 3 shelfButton code error

Maya 2022 Python 3 shelfButton code error

adnanmg
Advocate Advocate
662 Views
1 Reply
Message 1 of 2

Maya 2022 Python 3 shelfButton code error

adnanmg
Advocate
Advocate

Hi,

 

I'm updating some code to run with Maya 2022 and noticed that these lines:

 

 

names = cmds.shelfLayout(current_shelf, query=True, childArray=True) or []
labels = [cmds.shelfButton(n, query=True, label=True) for n in names]

 

 

for getting shelfbutton names and then labels is giving me the following error:

 

#     labels = [cmds.shelfButton(n, query=True, label=True) for n in names]
# RuntimeError: Object 'separator21' not found. # 

 

Is there a modified way to do this in Python 3?

 

I also tried creating a new shelf:

    # Create shelf if needed
    if not (cmds.shelfLayout(shelf_name, ex=1)):
        cmds.shelfLayout(shelf_name,  p='ShelfLayout')

 

This works, but the shelf is not visible anywhere.

 

Thank you,

 

Adnan Hussain

0 Likes
663 Views
1 Reply
Reply (1)
Message 2 of 2

brentmc
Autodesk
Autodesk

Hi,

 

I don't think your issue is related to Python 3 and you might need to filter out separators and/or include the shelf name when calling shelfButton.

e.g.

buttons = cmds.shelfLayout(shelf, q=True, childArray=True)
if buttons is None:
    buttons = []

for btn in buttons:
    if 'separator' in btn.lower():
        continue
    path = shelf + '|' + btn
    label = cmds.shelfButton(path, q=True, label=True)
    ...
 
Brent McPherson
Principle Software Developer
0 Likes