若要将 MEL 脚本与热键关联,必须先将脚本添加到可用热键命令列表中,然后为创建的命令指定热键。
例如,在文本框中键入 m 并启用 Alt 设置,可以为标记菜单指定 +m。
在编辑这些设置时,Maya 会显示当前为热键指定的命令(如果有)。请仅在不介意覆盖此命令时指定热键。
“按下”(Press)和“释放”之间的区别非常重要,例如在为捕捉模式指定热键时。即:为按下键指定启用捕捉模式的命令,为释放键指定禁用捕捉模式的命令。
如果设置的热键已经指定了命令,Maya 将询问是否要覆盖此命令。
使用以下 MEL 脚本可以创建 X 射线显示和线/着色模式之间的切换。
脚本 1:
/MEL to toggle xray mode on/off //map to a hotkey //get the current panel as xray mode works per panel $currentPanel = `getPanel -withFocus`; //get the state of xray mode (either on or off) $state = `modelEditor -q -xray $currentPanel`; //set it to the opposite state modelEditor -edit -xray (!$state) $currentPanel;
脚本 2:
//MEL to toggle cameras and image planes on/off //map to a hotkey $currentPanel = `getPanel -withFocus`; $state = `modelEditor -q -cameras $currentPanel`; modelEditor -edit -cameras (!$state) $currentPanel;