Add a shelfbutton to active shelf by code

Hi,
I’ve been using this forum for a very short period of time, and so far it’s being really helpful.

Here i go again with another question:

I’m trying to automate the installation of four shelf buttons that run some python and mel functions and procedures.

I want the animator to execute this script from the MEL command line and have those four buttons added to the current active shelf but i’m not capable of doing it. I’m trying first with a test button.
Here is one of my attempts in code:

global proc install_deep_tentacles()
{
//we get the main maya window
global string $gMainWindow;
string $win = $gMainWindow;
string $tabs = `tabLayout`;
//line to select current shelf
string $shelf = `shelfTabLayout -q -selectTab $tabs`;

//creation of the button
$buttonLabel = "TEST";
shelfButton -i1 "pythonFamily.png" -l $buttonLabel -command "print(\"hello\")";

showWindow $win;
}

any ideas on this?

Many thanks in advance!

HI! i already got it, discovered scriptToShelf mel command!!! that does the trick !!! thanks!!

What you needed was just adding

setParent $shelf;

before adding the button. Otherwise it doesn’t know where to add the button but the current window. :slight_smile: