Friday, August 14, 2009

Marking Menu Checkboxes and #1

So it's not difficult to realize that trying to learn the finer things about mel is like trying to learn about a language that doesn't even exist. The strange part about this, however, is that every once in a while you come across something implemented by Autodesk, which is seemingly documented nowhere. The even more difficult part about some of these situations, is that due to the wonderfully symbol-filled world of programming, trying to google "#1" is identical to trying to google "1". I'm not really sure what the functionality of the pound symbol is in other programming languages, and maybe that would've helped, but... Anyway, here is a neat feature in mel, of which I couldn't find information about anywhere on the internet. What I know about it is pretty much just from trial and error.

The #1 (pound 1) option is basically the future value of a menuItem's checkbox. So let's say you are in a marking menu with a checkbox called Happy (currently unchecked). If the -command (-c) of happy was "print #1", selecting Happy would output "1" in the script editor (which is now the value of the checkbox). The next time you select Happy (currently checked) the output would be 0 (now unchecked). So the usefulness of this comes in toggling one or more options with a checkbox item.

So let's take the example of toggling the selection mask of polys.
Instead of having to do something like...

menuItem
-l "Toggle Poly Mask"
-c "selectPref -polymesh (!`selectPref -q -polymesh`)"
-checkBox (`selectType -q -polymesh`);


you could simply use

menuItem
-l "Toggle Poly Mask"
-c "selectPref -polymesh #1"
-checkBox (`selectType -q -polymesh`);


Sure not a huge change with only one option, but it definitely came in handy when I was changing about 14 options at once. Trying to use #1 in any other situation but a checkbox command will return a syntax error (you can use it in menuItem checkboxes or even regular checkboxes), so you'd have to use the not (!) technique in such situations. Anyway, putting this out there because it's always nice to have quick answers to quick questions.

No comments:

Post a Comment