Hi all, I have some trouble in finding ways to call python functions inside of a mel script.
Basically, I have a few Mel scipts in which one creates a new shelf in Maya and inside it, are a few lighting tool button(spotLight, areaLights etc.)
As I am still a noob in scripting, not to mention that so far I have only been studying in python, as for mel I know a little to
none. This is quite a big obstacle for me. I am trying not to edit any of the scripts too much, so as to reduce confusion and any
errors that my occur.
- In my startup code, there are a few button which uses .xpm and .png for its icon. In the last few lines, the ext initially is .xpm but I change it to .png which I think it is wrong after I realised that I am still in need of some .xpm icons.
So is there a OR function in mel?
global proc shelf_lighting()
{
if (Dpublishmel("objGetMultiConfigs \"objkind\" \""+$show+"\" \"\" \"\" \"maya\" 1", $result))
{
string $kindRows[] = stringToStringArray($result[0], ";;");
$objkinds = $kindRows;
}
string $aboutString = `about -v`;
string $aboutStringArr[] = stringToStringArray($aboutString, " ");
string $versionStringTemp = $aboutStringArr[0];
string $versionString = match("[0-9]+[\.]*[0-9]+", $versionStringTemp);
float $version = $versionString;
string $pycmd = "evalDeferred \"python(\\\"^1s\\\")\"";
string $ext = ".png";
if ( int($version) > 2009 )
{
$ext = ".png";
}
- I am trying to change the command from “source “rexLightFuncs.mel”;
rexSpotLightCreate “”;”`; to the one as shown in the code below.
It is a python function and I am trying to incorporate it into mel
import DLightBuild.DLightBuild as build
light=build.DLightBuild();light.createLight('spotLight');
The file of this python commands comes from /tools/utils/maya/python/DLightBuild, containing the .py file - DLightBuild, and for some reason, it is not working as I derived this from an example I have seen somewhere in my google search.
$spotLightButton = `shelfButton
-enableCommandRepeat 1
-enable 1
-width 34
-height 34
-manage 1
-visible 1
-label "Create a Spot Light"
-image1 "spotLight.png"
-style "iconOnly"
-command "import sys;sys.path.insert(0, \"/tools/utils/maya/python/DLightBuild/\");import DLightBuild.DLightBuild as build;reload(build);light=build.DLightBuild(); light.createLight('spotLight')"
-sourceType "python";
- Lastly, whenever when I tried to do a test run of my code, to see if the icon image are right and if it is performing the correct function… If I run it just by the
shelfButton
as seen in the second part of the code (in Mel by the way), it creates a button at the end of my scriptEditor (it is like another docking window below) instead of in my existing shelf or in a new shelf. Any advices on this?