Question

Im trying to fire a python function using a button created with MEL. So I just wanted to know whether or not im understanding the docs correctly, so I just used a simple print call to test whether or not im correct in my assumption; this is what I tried out:

button -label "TransX" -w 100 -c python ("print 'Hello You!'");

However this won't fire at all (or if it does, it's doing something different than printing it in the script editor :/)

Even more curious to me was that if I wrapped it up in ticks like this:

button -label "TransX" -w 100 -c `python ("print 'Hello You!'")`;

it fired immediately (upon sourcing) and not while pressing the button. If anyone could explain that behaviour, that would be neat.

So what it boils down to is this: 1.How do I run a python function using mel properly? 2.Why the heck does the wrapping in ticks fire the python immediately?

Thx for your help :)

Was it helpful?

Solution

Using backticks will evaluate the contents as it's being executed, thats why you are seeing the print statement as soon as you run it

The first command doesn't work because you aren't encoding the argument to the "-c" flag properly, it should be like this :

button -label "TransX" -w 100 -c "python(\"print hello\");";

This way everything between the quotes gets passed to the "button" command to be used with the "-c" flag, and thats why you have to escape the inner quotes, so when the button command evaluates it, it will be evaluated as :

python("print hello");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top