mel shelf coding

26 views
Skip to first unread message

likage

unread,
Jul 15, 2016, 6:59:10 PM7/15/16
to Python Programming for Autodesk Maya
Apologize in advance that this is non-python related question but it is still related to maya though.. But I need some help in mel commands for this shelving of mine..

Say I have this shelf_funcs.mel that contains the setup or initialization of those shelf buttons..
One of its functions is as follows:

global proc shelfFuncs_paint()
{  
    shelfButton
       
-enableCommandRepeat 1
       
-enable 1
       
-width 34
       
-height 34
       
-manage 1
       
-visible 1
       
-annotation "spPaint tool for SITE"
       
-label "spPaint"
       
-image1 "iconTest.png"
       
-style "iconOnly"
       
-stp "python"
       
-command "import paintGUI;reload(paintGUI);paintGUI.paintGUIWin()"
       
;
}

Then I have another file - let's called it shelf_misc.mel that was called in Maya startup in which it then calls for shelf_funcs.mel
Pertaining to the above function, this is how it looks like in the shelf_misc.mel
global proc shelf_miscTools()
{  
   
eval( "source shelf_funcs.mel" );
   
...
   
...
    shelfFuncs_paint
();
   
...
   
...
}

So if this paintGUI script exists within the python directory of Maya, it will creates its own icon and be present in the shelf. Now my question is, how do I make it conditional in the shelf_misc.mel such that if the paintGUI.py does not in the directory, it should not create the icon?

Currently the icon is still present and unless if I click on it, an error will occurs stating '# ImportError: No module named paintGUI # '

Justin Israel

unread,
Jul 15, 2016, 7:36:00 PM7/15/16
to Python Programming for Autodesk Maya
Could you return an int from your shelfFuncs_paint() to indicate success or failure? Then you could test importing the python module before creating the button. If you failure to import the module then return 0. Otherwise return 1.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e8ae88cd-a2f1-4e3c-81c3-38112a8a50b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages