Wednesday, August 24, 2011

QT, QT designer and Maya

Well I started to take the plunge into using the QT framework inside of Maya. I feel I have become comfortable with the regular interface tools maya has built in but it seems the industry has more and more TDs using QT inside and outside of DCC apps so better learn it right. I just thought I would post some links to some good resources that helped me start it up fairly quick. Once I get it down I plan on making a couple simple tutorials on how to get started. Here are the links:

iVolxel studio blog:

This guy Chris has more than just ONE good link, look around his site:

One from the Area:

Monday, August 22, 2011

Finding out what button you clicked and how to get rid of it

Recently I was coding a tool and thought it would be cool to add a feature that allowed the user to right click on a button and then select a menu option to delete it. The question that arose was this: How do I figure out what button was pressed?(since there was a whole bunch of them and they were being created dynamically). There is most likely a better way to tackle this but since there is no immediate answer and i'm slightly retarded here is what I came up with as a solution.

Here is the code:

import maya.cmds as cmds
from functools import partial

def delFunction(btn, *args):

win = cmds.window()
fullPathName = cmds.button(btn, q=True, fpn=True)
cmds.button(btn, e=True, c=partial(delFunction, fpn))


Basically what I did was create the button then grab the fullPathName of the button in the UI, this gives me what button it is. Then I pass that button into the function that deletes it using the 'partial' function from functools. Partial allows one to pass in an argument(s) to a function while in the command field. Then I simply use the deleteUI command and pass in the button I want to get rid of. Easy really, it's just a matter of figuring it out.

Right-click Menu in Maya using Python

This might be a little obscure but thought I would throw this out there for anyone who searches this with Google. I know it was frustrating to find any kind of real resource on the subject so here it is. You can add a right-click pop-up menu to pretty much any UI element with Mel/Python in Maya. Here is a link to the docs about this menu:

Take a look at the example. Not too informative but basically all you need is a parent to attach the menu to and set the button to be the RMB, and you are done!


import maya.cmds as cmds

win = cmds.window()
btn = cmds.button(l='Click Me')
popup = cmds.popupMenu(parent=btn, ctl=False, button=3)
item1 = cmds.menuItem(l='Item1', c='whatever and')
item2 = cmds.menutItem(l='Item2', c='whatever')


and there you go! That's really all there is to it.