Making a PYTHON script run from a MEL shelf button


#1

Hello !

I’ve searched all the way to find a way, but that thing is really driving me crazy ! :banghead:

I have a MEL shelf button, and I’m trying to run a python command into it. I discovered the python command and I tried to use it.

The thing is, it works if I put it directly in Maya ( buy right-cliking the shelf button > edit ). But if I put the exact same code into my shelf file, It doesn’t works anymore.

    shelfButton
        -enableCommandRepeat 1
        -enable 1
        -width 35
        -height 35
        -manage 1
        -visible 1
        -preventOverride 0
        -annotation "TEST" 
        -enableBackground 0
        -align "center" 
        -label "test" 
        -labelOffset 0
        -rotation 0
        -flipX 0
        -flipY 0
        -useAlpha 1
        -font "plainLabelFont" 
        -overlayLabelColor 0.8 0.8 0.8 
        -overlayLabelBackColor 0 0 0 0.2 
        -image "/u/mgl/maya2016-x64/icons/test/test.xpm" 
        -image1 "/u/mgl/maya2016-x64/icons/test/test.xpm" 
        -style "iconOnly" 
        -marginWidth 1
        -marginHeight 1
[B]	-command "python ("import sys");"
        -sourceType "mel" [/B]
        -commandRepeatable 1
        -flat 1
    ;

So here are the results I have:

-command “python (“import sys”);”

= On maya starts, I have a warning " Shelf Error: The Shelf “test” has items that cannot be read … "

-command “python ('import sys);”

= Maya starts normally, but if I launch the button, I have a syntax error:

// Error: python (‘import sys’); //
// Error: Line 1.9: Syntax error //

What am I doing wrong here?

Thank you guys !!


#2

Masking the quotes should help:

-command "python (\"import sys\");"


#3

DAMN ! Thank you so much ! :keenly: