How to make a Toggle Script for switching MoveTool settings?


#1

Hi everyone,

First time posting here, please forgive any mistakes.

I’m trying to create a MEL script that allows me to cycle between Move Falloff modes when using Transformation Tools in the Graph Editor (cycling between Constant, Linear and Exponential).

MoveTool

Unfortunately I don’t know how to script, and have trouble following the Maya MEL documents.
All I have so far is this script someone on Twitter posted, but I have no idea how to get it to work (here’s the original Twitter post: https://twitter.com/tjgalda/status/1194763198362054656:

======

string $runCommandCmd = (“runTimeCommand -category “User” -c (“moveKeyCtx -e -moveFunction \“linear\” \“moveKeyContext\””) graphKeysFalloffDown;” );
eval($runCommandCmd);

string $nameCommandCmd = (“nameCommand -ann “graphKeysFalloffDown” -c “graphKeysFalloffDown” graphKeysFalloffDown;”);
eval($nameCommandCmd);

string $runCommandUpCmd2 = (“runTimeCommand -category “User” -c (“moveKeyCtx -e -moveFunction \“constant\” \“moveKeyContext\””) graphKeysFalloffUp;” );
eval($runCommandUpCmd2);

string $nameCommandUpCmd2 = (“nameCommand -ann “graphKeysFalloffUp” -c “graphKeysFalloffUp” graphKeysFalloffUp;”);
eval($nameCommandUpCmd2);

hotkey -keyShortcut “!” -name (“graphKeyFalloffDownName”);
hotkey -keyShortcut “!” -releaseName (“graphKeyFalloffUp”);
savePrefs -hk;

======

I also found out that running these two lines separately can change the tool. Doesn’t work for exponential strangely:
moveKeyCtx -e -moveFunction “constant” moveKeyContext;

moveKeyCtx -e -moveFunction “linear” moveKeyContext;

Any help much appreciated!!


#2

Maybe something like this.

string $falloffMove = `moveKeyCtx -q -moveFunction moveKeyContext`;

if ($falloffMove == "constant") {
    moveKeyCtx -e -moveFunction "linear" moveKeyContext;
}
if ($falloffMove == "linear") {
    moveKeyCtx -e -moveFunction "power" moveKeyContext;
}
if ($falloffMove == "power") {
    moveKeyCtx -e -moveFunction "constant" moveKeyContext;
}

#3

Amazing, it’s exactly what I was looking for! Was totally unaware of falloffMove. Thank you!