cmds.button (python, callbacks, maya 2013) , takes no arguments, one given

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  04 April 2013
cmds.button (python, callbacks, maya 2013) , takes no arguments, one given

EDIT: I learned some for it to work, but please read nontheless
sorry for the misrable english, I'm dead tired...

Sorry to create one more of these,. I have read the others and read the pymel doc about it but I'm still having issues.

As you can see, I haven't begun using PYMEL so I'm wondering, are there any issues if I should start using it seeing as it's a 3rd party module. I guess the only limitation would be only for earlier Maya versions before python, but I don't plan to switch back to <8.5.

And as far as I can tell, Autodesk are just happy to ship it with Maya seeing as it's quite a big success.

Reason I'm asking is if I should just go ahead and use some of pymels functions or are there other ways by only using maya's python module?
Jeremy Ernst creates a new def() for the purpose of issuing a command to be executed by Mayas button command(26.00 mins in the video below). This works, but I was just looking for a cleaner approach and since I'm learning....

So anyway. This is my code, copied from Jeremy Ernst's vimeo tutorials.

import maya.cmds as mc
import maya.mel as mel
import os
widgets = {}

def UI():
    if mc.window('exampleUI', exists=True):
    widgets['window'] = mc.window('exampleUI', w=50, h=50)
    widgets['scrollLayout'] = mc.scrollLayout(hst=0)
    widgets['mainLayout'] = mc.columnLayout(adj=True, parent=widgets['scrollLayout'])
    #find icopn, create button
    mc.window(widgets['window'], edit=True, w=180, h=500, sizeable=False)
def populateIcons():
    iconPath = mc.internalVar(upd=True)+'icons/testIcons/'
    if os.path.exists(iconPath):
        icons = os.listdir(iconPath)
        categories = []
        for icon in icons:
            categoryName = icon.partition('__')[0]
        for categoryName in categoryNames:
            widgets[(categoryName + '_frameLayout')] = mc.frameLayout(label=categoryName, collapsable=True ,parent=widgets['mainLayout'])
            widgets[(categoryName + '_rowColLayout')] = mc.rowColumnLayout(nc=3, parent=widgets[(categoryName + '_frameLayout')])
        for icon in icons:

            niceName = icon.partition('.')[0]
            category = icon.partition('__')[0]
            commandName = icon.partition('__')[2].partition('.')[0]
            widgets[(niceName + '_button')] = mc.symbolButton(w=50, h=50, image=(iconPath+icon), parent=widgets[(category+'_rowColLayout')], c = lambda *args: command(commandName) )
#            widgets[(niceName + '_button')] = mc.symbolButton(w=50, h=50, image=(iconPath+icon), parent=widgets[(category+'_rowColLayout')], c = ('command(%s)' % commandName) )

def command(cmd):
    print cmd

and here's the icons which are just for test. Supposed to be placed in maya/prefs/icons/testIcons/icons.xpm

Thanks for any inputs and ideas.

EDIT: Actually I followed along and tried to just use the one method with partial etc and it works as I had hoped.

PS. I still would like to know the answers to my questions on PYMEL.

Thanks again

Last edited by Geuse : 04 April 2013 at 10:58 PM.
  04 April 2013
With pymel you can create a cleaner code.

e.g. you can simply create a button:

import pymel.core as pm
def buttonCmd():
 	print "Button command"
 bt = pm.button(label="Test", cc = pm.Callback(buttonCmd))
 tt = pm.textFieldGrp(label="TextField", text="blabla") 
 theText = tt.getText()

What is much easier to read than:

theText = cmds.textFieldGrp(theTextField, query=True, text=True)

Same with windows. You can simply subclass from a pm.Window() class and add your methods. This way you can keep all data in your window class what makes callback handling quite easy without the need of any global variables.
__________________ -
  04 April 2013
In your code example you could add "import pymel.core as pm" and then replace all your mc's with pm's and it would probably still work. But if thats all you did it would hardly be worth the effort. The reason I like pymel is that it returns objects (PyNodes) instead of names (strings). Objects (like Classes) have methods that I think are nicer to work with than the mel like functions from maya.cmds.

Simple examples:
obj = pm.PyNode('pCube1')

obj = 'pCube1'
mc.setAttr(obj+'.tx', 10)

Both can get the job done. I prefer object oriented pymel.

  04 April 2013
Thanks a bunch to the both of you!
  04 April 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 02:50 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.