CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 04-03-2013, 10:44 PM   #1
Geuse
Expert
 
Geuse's Avatar
portfolio
Dag
Sweden
 
Join Date: Apr 2006
Posts: 518
Send a message via MSN to Geuse
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.
http://www.luma-pictures.com/tools/...ocs/1.0/ui.html
http://forums.cgsociety.org/showthread.php?t=989318

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.
https://vimeo.com/44707576

Code:
import maya.cmds as mc import maya.mel as mel import os widgets = {} def UI(): if mc.window('exampleUI', exists=True): mc.deleteUI('exampleUI') 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 populateIcons() mc.showWindow(widgets['window']) 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] categories.append(categoryName) categoryNames=list(set(categories)) 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
https://dl.dropbox.com/u/16029672/3D/testIcons.rar


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-03-2013 at 10:58 PM.
 
Old 04-04-2013, 10:55 AM   #2
haggi
Expert
3d freelancer
 
Join Date: Apr 2004
Posts: 930
With pymel you can create a cleaner code.

e.g. you can simply create a button:

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


What is much easier to read than:

Code:
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.
__________________
www.renderwiki.com - www.openmaya.net
 
Old 04-04-2013, 11:15 AM   #3
djx
Where's my pony?
 
djx's Avatar
David Johnson
vfx & creature td
Melbourne, Australia
 
Join Date: Jun 2003
Posts: 3,389
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:
#pymel...
obj = pm.PyNode('pCube1')
obj.tx.set(10)

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

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

David
__________________
http://www.djx.com.au
 
Old 04-04-2013, 12:19 PM   #4
Geuse
Expert
 
Geuse's Avatar
portfolio
Dag
Sweden
 
Join Date: Apr 2006
Posts: 518
Send a message via MSN to Geuse
Thanks a bunch to the both of you!
 
Old 04-04-2013, 12:19 PM   #5
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 10:36 AM.


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