View Full Version : Some MEL questions:
1. How do I tell Maya to change one option while one tool is selected, and change it back when exiting the tool? The tool is the facepath selection tool from the BonusGames pluginpack from AW, and as I'm always using the "select whole face" option for selecting faces, the facepath tool doesn't work as it needs the "select center" option. I also know the command for changing the option (polySelectConstraint -ws 0/1;), but don't know how to make it change when entering the tool and exiting the tool.
2. I've now tried many times to make a hotkey to show/hide the UI, but haven't succeeded yet. What I've tried to do, is to assign a global variable in usersetup.mel at the start of maya, named "$isUIhidden" and assigning 0 to it. Then I've tried to make a simple if conditional checking the "$isUIhidden", and if it's 0, then run "HideUIElements;" and make the "$isUIhidden" 1, and else if statement where if "$isUIhidden" is 1, then run "restoreUIElements;" and make the "$isUIhidden" 0.
This though doesn't work at all, if I run it, it will always assign 0 to the $isUIhidden, no matter what it was at start, I've read that you have to declare global variables in every procedure used, and I think I've done that right too, though I'm not sure of it.
Now I have the UI hide setup so "a" hotkey runs the "HideUIElements;" and "shift + a" runs the "RestoreUIElements;", but I'd like to have only one button for it.
3. Why can't the "if" conditional accept "=" or "==" as the condition? If I want to test if $examplevar is 0 or 1, I have to write it "if ($examplevar > 0)" and "else if ($examplevar < 1)", normal "if ($examplevar = 0)" doesn't seem to work?
4. Could someone explain the difference between ``, () and eval() abit more clear, as I really didn't understand what the manual said. As eval() is supposed to have delayed evaluation, but I got the impression it is evaluated immediately? :surprised ... I'm confused.
Ok can't think of anything else for now, I hope even some of 'em get answered.
|
|
ACFred
05-27-2002, 06:22 AM
I only have time right now to post the answer to #3 since it takes the least amount of time.
In MEL, as in C syntax, the single "=" represents an assignment, meaning that you're making one value equivalent to another.
The double equal sign ("==") is an equivalency check. Is X equal to Y? That's why you have to use "==" when you're creating a loop because you're checking for an equivalency condition and not assigning a new value to a variable.
Hope that makes sense. I'll look at the other questions later tonight if I get the chance.
Weird, as I'm pretty sure I tried once with "==" too, but it was the same as if I'd used only one "="... I'll try again, thanks for clarifying that.
bigfatMELon
05-30-2002, 06:02 AM
#1 is complicated. There are a few ways, ranging in complexity.
The simplest, dirty way would be to make your own hotkeys to access the tool and write the toggle state into that key.
Another way, slow and more cludgey yet more automatic) would be to create a scriptJob node to evaluate whether the tool in question is active or not and then toggle the state based on that result.
The third way depends heavily on the code for the tool itself. You could alter the code for it and either add your own evaluation or a callback script.
If I wanted to get it done in 10 minutes or less, I'd go with the first one.
#2 was answered very well already
#3
`` = get the result of the action contained within
() = do what's in here first. It can become confusing when you encounter math functions such as size, gauss and rand which appear to work like ``. The easiest thing to do is keep in ming whether you are calling a mel command or a math function and it should become more clear.
eval () has almost nothing in common with either of the above in that it doesn't force the execution order to change, nor does it pass the result of anything. It is essentially useful for writing self building/modifying code.
for instance, if you would like you script to be able to build n number of global variables (they'd have to be globals to do any good because scripts executed by eval take place within their own scope), you could do it as such:
//build variables from a list of strings
string $y[] = {"$a", "$b", "$c"};
for ($x in $y){
eval (("global string " + $x + ";"));
}
-jl
Thanks bigfatMELon!
I think I'd like to know how to do it by altering the code itself of the tool, AKA "the third way". I think it would help the most for learning more MEL, and I don't see it as too "cheat-like" the other two ;)
Thanks for the explanation for #3! Now I quite understand them better.
The ``'s don't really run the action as is, but just assigns the return value to the place where the ``'s were?
I think I somewhat understand the ()'s too.
And now I finally understand the eval syntax, thank you very much for that!
Though I still have one question regarding these ``'s, ()'s and eval's... if I want to get i.e. a boolean of a value which is either on or off with a loop, I will declare an int like "int $example = `exampleFunction -query OnOrOff`", but when I run the script, does the action inside the ``'s get executed only once, as it seems like it when querying the value, modifying the value in the script and then querying it again, it always seems to return the same value. Am I just using the wrong method by using the ``'s?
(Sorry for the messy text... my english seems to be getting more worse and worse everytime I type something...)
bigfatMELon
05-30-2002, 04:07 PM
>I think I'd like to know how to do it by altering the code itself of the tool,
>AKA "the third way". I think it would help the most for learning more MEL,
>and I don't see it as too "cheat-like" the other two
You'll dig to track down the code where that happens and figure out what AW is doing there. And, of course, you'll need to be careful about it.
>will declare an int like "int $example = `exampleFunction -query OnOrOff`",
>but when I run the script, does the action inside the ``'s get executed only
>once, as it seems like it when querying the value, modifying the value in the
>script and then querying it again, it always seems to return the same value. >Am I just using the wrong method by using the ``'s?
The only way to take the value of a command result is to use ``. When you encase a command with ``, whatever the contents are executed once within those quotes and the resulting value serves in it's place. You can always call the same command again if you need to do it at two different places.
In terms of the returned result being the same, I'd say that the result is correct and you are mistaken about what the correct returned result should be. That is the case 99.99% of the time with programming.
-sj
Ok I'll propably look at the script today, and see if I can understand it. I'll try to look if I'd have any other scripts that would do something at the load/unload and look at them too.
And about the variables, yeah, maybe I've just mistaken, as I discovered that when I was incorrectly using the if with "=" rather than "==", so it propably confused it, thanks.
bigfatMELon
05-30-2002, 07:56 PM
And about the variables, yeah, maybe I've just mistaken, as I discovered that when I was incorrectly using the if with "=" rather than "==", so it propably confused it, thanks.
Oh yah. The funny thing about if ($x = 1) is that it won't break the script but instead will always equate to true. That's because all assignments are always true. You are stating that $x is equal to 1 and that is absolutely true. This prevents the else branch from ever seeing the light of day.
BTW, this mistake is one of the most common programming errors ever and still haunts me after 10+ years.
-jl
CGTalk Moderation
01-13-2006, 07:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.