save button to shelf

Become a member of the CGSociety

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

Thread Tools Display Modes
  05 May 2012
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

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

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;
                     -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)
  05 May 2012
Turning on the echo all commands and saving a script to a shelf gives:

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

So execute this mel command from python.
  05 May 2012
Thanks zoharl, this will do the job
  05 May 2012
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:
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)
  05 May 2012
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
  05 May 2012
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 12:22 PM.

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