通常、ホットキーを登録するには Hotkey Editor (Window → Settings/Preferences → Hotkeys...)を使用します。
MEL コマンドによってホットキーの登録・リストアップ・消去を行いたい場合は、
nameCommand, runTimeCommand, hotkey コマンドを使用します。
hotkey コマンドによって、ホットキーを登録する時は、
以下の手順によって行ないます。
hotkey コマンドだけでは、ホットキーの登録はできないことに注意して下さい。
hotkey コマンドによって、
sphere;
move 1 2 3;
というコマンドを実行するホットキーを、
割り当てられていない文字をさがして自動的に登録してくれる
MEL スクリプトを作ってみましょう。
ホットキーに割り当てられる文字は ctrl + 英小文字 としています。
また、ホットキーの名前や註釈は適当な文字列を登録しているので、
変更したい場合は Hotkey Editor で行ってください。
proc string [] findUnmappedCtlKey()
{
string $alpha[] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
string $unmap[];
int $i = 0;
for($char in $alpha)
{
if(`hotkey -q -ctl -k $char` == 0)
{
$unmap[$i] = $char;
$i++;
}
}
return $unmap;
}
proc setMyHotkey(string $key, string $com)
{
string $name = ("myHotkey_ctl_" + $key);
nameCommand -annotation ("My hotkey Ctl+" + $key) -command $com $name;
runTimeCommand -annotation ("My hotkey Ctl+" + $key) -command $com -category "User" $name;
hotkey -k $key -ctl -name $name;
}
global proc setHotkey1()
{
string $unmap[] = findUnmappedCtlKey();
if(`size $unmap` > 0)
{
string $com = "sphere; move 1 2 3;";
setMyHotkey($unmap[0], $com);
}
else
{
warning "Not Found Unmapped key";
}
}
proc string [] findUnmappedCtlKey()
string $alpha[] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
string $unmap[];
int $i = 0;
for($char in $alpha)
if(`hotkey -q -ctl -k $char` == 0)
$unmap[$i] = $char;
$i++;
return $unmap;
proc setMyHotkey(string $key, string $com)
string $name = ("myHotkey_ctl_" + $key);
nameCommand -annotation ("My hotkey Ctl+" + $key) -command $com $name;
runTimeCommand -annotation ("My hotkey Ctl+" + $key) -command $com -category "User" $name;
hotkey -k $key -ctl -name $name;
global proc setHotkey1()
string $unmap[] = findUnmappedCtlKey();
if(`size $unmap` > 0)
string $com = "sphere; move 1 2 3;";
setMyHotkey($unmap[0], $com);
else
warning "Not Found Unmapped key";
hotkey コマンドでホットキーの登録を行うときは、 以下のような組み合わせが可能です。