Reputation: 1581
I am pretty new to MEL and as I was exploring around this MEL script, I found out that the user have write some lines that I totally do not get it. And yet I am interested to know why this person done it..
Anyway, can someone kindly explain why does the following code, first indicate an empty MEL then it goes on to call a Python? Wouldn't it be easier to just put in the Python?
I also tried to disable the command and sourceType, and the script works fine too, it is just that I do not get what is the purpose of command
and sourceType
doing in this case...
-command ""
-sourceType "mel"
-actionIsSubstitute 0
-commandRepeatable 1
("shelfBtn_" + $parent + "_AOV");
python("import aovsFunction as aovs; aovs.MenuFuncs.aovMenu('"+"shelfBtn_" + $parent + "_AOV"+"')");
By the way, $parent
is derived from:
global proc apkg2dnc(string $parent)
Then I tried to change the code into the following, it works as like the one above but...
-command ("import aovsFunction as aovs; aovs.MenuFuncs.aovMenu('"+"shelfBtn_" + $parent + "_AOV"+"')")
-sourceType "python"
When I tried removing the brackets, I was given the Syntax Error message, indicating the first plus sign +
that it encounters.
Did tried to add in the ;
at the end of the line, it is still giving the Syntax Error, this time indicating at the start of the line
-command "import aovsFunction as aovs; aovs.MenuFuncs.aovMenu('" + "shelfBtn_" + $parent + "_AOV" + "')"
-sourceType "python"
And so, does brackets play a big part in how it is being read in MEL?
Upvotes: 0
Views: 1292
Reputation: 4434
Your examples are malformed. In general you can not cut code from switches like you are doing because the code looses meaning. Switches like:
-command ""
are referring to the line before where the actual mel command is invoked (not to be confused with the -command switch). In this case i would guess the entire command is actually:
shelfButton
-command ""
-sourceType "mel"
-actionIsSubstitute 0
-commandRepeatable 1
("shelfBtn_" + $parent + "_AOV");
But it is hard to know. The code looses all meaning if you omit the command being called and can for most part not be understood that way as it has no meaning. Its like a sentence without a subject, predicate and context.
With that clarified we can actually answer the question. Why put a a empty -command? Its a bit redundant, yes but it still has meaning. The reason is that he does not know what to populate the button with. You could omit the command and source type flags shouldn't make a difference. (there is a off chance that omitting source type would end up being subtly wrong)
The next command does the binding:
python(...yada yada ... "('"+"shelfBtn_" + $parent + "_AOV"+"')");
No i have no idea what aovMenu really does but the intention is pretty clear because he is passing the name of the button. Whatever is inside the aovMenu command is changing the command of the button. This would off end up looking like it worked if you put it into -command switch directly (because pushing the button the first time would populate the button). But it would be subtly wrong, nonetheless.
This is a pretty common pattern in maya programming. What you do is you pre-generate the button to know its final name so that you can bind two entities that depend one each other to that name.
goes on to call a Python? Wouldn't it be easier to just put in the Python?
Not really the code would be exactly the same. It might be easier this way, depends on who is calling. You would still need to bootstrap the button and then call the aovMenu function. Its not really any different form calling a function made by somebody else.
The thing is the code is a bit bad, there is a small chance for a subtle error. It wouldn't matter if it was written in python or not but rather how Maya behaves. You can not actually know the button will be called:
("shelfBtn_" + $parent + "_AOV")
Because if that name exists maya will rename it OR worse name it the same as something else and now you have to use the full path name or get a 50% chance of error. the correct way to do this would be thus:
$sButton = `shelfButton
-actionIsSubstitute 0
-commandRepeatable 1
("shelfBtn_" + $parent + "_AOV")`;
python("import aovsFunction as aovs; aovs.MenuFuncs.aovMenu('"+$sButton+"')");
Upvotes: 4