How to ctrl + click on shelf , and shelf runs?

I’m thinking of a way so that when ctrl+click on a shelf, that shelf will run.
If you click normally, it will run another shelf.
Does anyone know how to do it?
I tried searching but didn’t see any examples.

Do you mean like running every script on a shelf?
Would this not be better served as a window or just an actual single script in this case?

1 Like

What I mean is, when I click on shelf, it will run script 1.
When you click + ctrl (or alt) on that shelf again, it will run script 2.

it probably won’t be much help just looking at a few cases.
but exponentially, it will save working UI area, click time, number of shelves…

it’s very easy to do in principle, but making it somehow generically applicable to any existing shelf button via coding would be the tricky part.
Essentially, you can just use the getModifiers command to see if CTRL is being pressed. If it is you run one command, if not, another. Just paste/drag this code on a Python shelf button:

from maya import cmds
if cmds.getModifiers() == 4:    # (4 is CTRL)
    cmds.polyCube()
else:
    cmds.polyCone()

This would work exactly the same in MEL btw.

that’s great, thank you. I searched forever.
but Where did you get the button code?

Where did you get the button code?

I’m not sure I understand the question… :thinking:
The “button code” above I just typed in off the top of my head. Or do you mean how did I know 4 is the code for the CTRL button? - that is detailed in the getModifiers documentation (if you’re not familiar with accessing the command docs, I’d sort that out asap: Python Command Docs )

Or were you asking if it’s possible to get the code on an existing Shelf Button? It is, you can just do:

cmds.shelfButton("shelfButton13", query=True, command=True)

but it’s slightly more involved than that in practice, as there’s no straightforward way to know or find out the name of the shelf button you are interested in. You have to query the shelf layout, get it’s children, then find your shelfButton somehow by matching the icon, or something in the command string, or some other property, and it’s a bit awkward tbh.

wow, yes, that i mean. thank you <3