CGTalk > Software Specific Forums > Autodesk Maya > Maya Programming
To minimize the ads you see on this page create a CGTalk account and log in HERE
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 05-12-2012, 07:20 PM   #1
nookie
Know-it-All
 
nookie's Avatar
portfolio
Luca Fiorentini
Lighting Artist
Lucasfilm Animation
Singapore, Singapore
 
Join Date: Jan 2004
Posts: 367
Send a message via MSN to nookie
save button to shelf

Hi all,

I was trying to save a button to the current active shelf with python but with not so much luck.
Let's say I want to save a button doing this

Code:
print 'hello I am a button'


Which would be the best way?
I was taking a look at the way maya saves a camera bookmark to the shelf

Code:
global proc cameraBookmarkShelfCB(string $parent, string $camera) { setParent $parent; string $item = selectedBookmark(); if ($item != "") { global string $gShelfTopLevel; if (`tabLayout -exists $gShelfTopLevel`) { string $currentShelf = `tabLayout -q -selectTab $gShelfTopLevel`; string $cmdStr = "cameraView -e -camera "+$camera+" -setCamera "+$item; shelfButton -p ($gShelfTopLevel + "|" + $currentShelf) -image1 "commandButton.png" -label $item -style `shelfLayout -q -style $currentShelf` -width `shelfLayout -q -cellWidth $currentShelf` -height `shelfLayout -q -cellHeight $currentShelf` -c $cmdStr; } } }


but I don't really know how to treat that $gShelfTopLevel variable (in python)
 
Old 05-13-2012, 08:06 AM   #2
zoharl
A newbie
 
zoharl's Avatar
portfolio
Zohar
A student
Haifa, Israel
 
Join Date: Mar 2009
Posts: 1,815
Turning on the echo all commands and saving a script to a shelf gives:

Code:
scriptToShelf "tmp" "print 'hi'" "0";


So execute this mel command from python.
 
Old 05-13-2012, 03:04 PM   #3
nookie
Know-it-All
 
nookie's Avatar
portfolio
Luca Fiorentini
Lighting Artist
Lucasfilm Animation
Singapore, Singapore
 
Join Date: Jan 2004
Posts: 367
Send a message via MSN to nookie
Thanks zoharl, this will do the job
 
Old 05-14-2012, 10:23 AM   #4
NaughtyNathan
HighEnd3D deserter
 
NaughtyNathan's Avatar
Naughty Nathan
Technical Artist
Sony SCEE Liverpool
Manchester, United Kingdom
 
Join Date: May 2008
Posts: 2,608
I'd also recommend making use of existing code by executing existing MEL functions via python as suggested, but just in case anyone wanted to know the python to do this:
Code:
import maya.cmds as mc import maya.mel as mel topShelf = mel.eval('$nul = $gShelfTopLevel') currentShelf = mc.tabLayout(topShelf, q=1, st=1) mc.shelfButton(parent=currentShelf, i='commandButton.xpm', c='print "hello I am a button",')
Ironically you still have to execute MEL code to get the global variable which contains the top level shelf layout... (although hard-coding topShelf to "ShelfLayout" would probably be safe for most normal users)
 
Old 05-17-2012, 05:16 PM   #5
nookie
Know-it-All
 
nookie's Avatar
portfolio
Luca Fiorentini
Lighting Artist
Lucasfilm Animation
Singapore, Singapore
 
Join Date: Jan 2004
Posts: 367
Send a message via MSN to nookie
Thanks Nathan!
I was having some troubles using the mel procedure while this is working perfectly!
I also was quite interested in how to get the value of those global variables
 
Old 05-17-2012, 05:16 PM   #6
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 09:09 AM.


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