Maya MEL eval

用 MEL interpretor evaluate 字串.

References:

eval/evalDeferred/executeDeferred

  • eval/evalDeferred/executeDeferred 是在 MEL 的 top level scope 執行, 所以 MEL 的 global variable 都可以讀的到.
  • eval 是立刻執行, evalDeferred/executeDeferred 則是在 CPU process 有餘裕在執行, 後者容易因為執行順序不同而產生錯誤. 例外狀況是在 Maya startup 時, 要覆蓋掉 maya builtin commands, 用 evalDeferred 可以等 maya 本身的 procedure 都存到記憶體之後在執行, 進而達到 override 的效果. (實務上常會執行兩次)
  • maya.utils.executeDeferred 是 evalDeferred 的 Python Alternative, 除了 string 以外它也接受 function(callable object)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
eval(...)
    Takes as input a string containing MEL code, evaluates it, and returns the result.

    This function takes a string which contains MEL code and evaluates it using
    the MEL interpreter. The result is converted into a Python data type and is
    returned.

    If an error occurs during the execution of the MEL script, a Python exception
    is raised with the appropriate error message.

executeDeferred(...)
    Delays the execution of the given script or function until Maya is idle.

    This function runs code using the idle event loop.  This means that the
    main thread must become idle before this python code will be executed.

    There are two different ways to call this function.  The first is to
    supply a single string argument which contains the Python code to execute.
    In that case the code is interpreted.

    The second way to call this routine is to pass it a "callable" object.
    When that is the case, then the remaining regular arguments and keyword
    arguments will be passed to the callable object

catchQuiet(MEL)

  • catchQuiet 等同於 python 的 try except
  • catch 等同於 python 的 try