Skip to content

Tweaking tweenMachine’s Buttons

“How can I customize the button values?”

This is, by far, the most common question I’ve received about my little tweenMachine tool.

While the default values may work well as you’re getting used to the tool, or perhaps getting used to using breakdown poses for the first time, there might come a time when you’d like to tweak those values.

If that time is now, read on.  (If not, bookmark this page for later reference.)

I have to do what?!?

Eventually there will be a settings dialog for the Python version that will make this process much easier. However, at the time I’m writing this post (early 2017), it’s still a manual task.  That’s right, you’re gonna get your hands “dirty” with a little code, but fear not.  I’ll walk you through it for both versions of the tool.

Python

Once you’ve imported the tweenMachine module, all tool settings are accessible via a dictionary named (ironically enough) SETTINGS.  (I’m not going to go into the ins and outs of Python dictionaries here; if you’re not familiar with them, review the Python docs.) The general pattern for changing anything in this dictionary is:

tweenMachine.SETTINGS["name"] = value

The setting name for changing button values is default_button_data. Without getting too technical, it’s structured as a series of nested containers – one for each button – like this:

( (value, (R, G, B)), (value, (R, G, B)), ... )
  • value: the button’s value as a whole number; i.e. -75 for 75% toward the previous pose, 66 for 66% toward the next pose, etc.
  • R, G, B: decimal values for the button’s red, green, and blue color components; i.e. 0.6, 0.6, 0.6 for the default mid-grey color.

If you want to see the current contents of this setting, just type the following into the command line (in Python mode):

tweenMachine.SETTINGS["default_button_data"]

Because of the number of values stored in this setting, it can be confusing to change via the command line. I recommend changing it in Maya’s Script Editor window, where you can format the whole change across several lines. Let’s say I wanted to change the outer-most buttons from their default -75 and 75 to -80 and 80.  In the Script Editor, I would type the following onto a Python tab:

tweenMachine.SETTINGS["default_button_data"] = (
    (-80, (0.6, 0.6, 0.6)),
    (-60, (0.6, 0.6, 0.6)),
    (-33, (0.6, 0.6, 0.6)),
    (0, (0.6, 0.6, 0.6)),
    (33, (0.6, 0.6, 0.6)),
    (60, (0.6, 0.6, 0.6)),
    (80, (0.6, 0.6, 0.6))
)

Each row of data in this example represents a button, with the first row representing the left-most button, and the last row being the right-most button.  To execute this, just highlight the selected code and either choose Command —> Execute from the Script Editor menu, click the blue Execute button (looks like a typical “play” symbol) on the Script Editor’s toolbar, or hit the Enter key on your keyboard’s numeric keypad (NOT the normal Enter key, which will erase what you’ve highlighted).  Once executed, restart tweenMachine to see the changes.

To give another example, perhaps I only want four buttons instead of seven, I want totally different values, and I want them all slightly red. I could do something like this:

tweenMachine.SETTINGS["default_button_data"] = (
    (-92, (1, 0.6, 0.6)),
    (-17, (1, 0.6, 0.6)),
    (17, (1, 0.6, 0.6)),
    (92, (1, 0.6, 0.6))
)

With the Python version, any number of buttons will work because it automatically sizes them horizontally to fit in the available space.  Feel free to use as few or as many as you wish.

The biggest headache with this method is that you must specify the values and colors for all buttons at once.  You can’t just reach in and change a single button without messing with the rest.  However, like I said, there will eventually be a dialog to make these changes easier, so you can change single buttons at will, or even save different button configurations for different situations.  For now, though, this is the way it must be done.

(The more adventurous among you might want to dig into the other available settings in this SETTINGS dictionary to see what else can be tweaked.  As with the button values and colors, most (if not all) of those options will eventually be accessible via a nice little UI.  I just need to find the time to build it.  *sigh*)

MEL

Those who are still using the MEL version have a slightly different – and slightly easier – process to follow.  However, there are some restrictions that make it less flexible as well.

Unlike the Python version, all of the MEL version’s button values get reset by the code every time you open tweenMachine.  Therefore you’ll need to change the code to change these values.

First off, you need to make sure you’re opening the version of tweenMachine that’s actually being used by Maya.  The easiest way to do this is to open the tweenMachine tool in Maya first, then type the following into the command line:

whatIs tweenMachine

This will give you the exact path to tweenMachine.  Open the file at that path in a text editor, preferably one that will maintain the file’s plain text nature.  In Windows, the built-in Notepad app is a good choice.  On the Mac, TextEdit will work.  If you have an editor that shows line numbers, that will make the job a notch easier.

In the current version of tweenMachine (2.1.1 at the time I’m writing this) the lines that set these values begin on line 199 of the script.  If your editor doesn’t support line numbers, simply search for “$tmButtonVal[0]”.  This will take you to the first of seven lines that set the button values:

...
    $tmButtonVal[0] = -75;
    $tmButtonVal[1] = -60;
    $tmButtonVal[2] = -33;
    $tmButtonVal[3] = 0;
    $tmButtonVal[4] = 33;
    $tmButtonVal[5] = 60;
    $tmButtonVal[6] = 75;
...

As you’ll see, there’s one line for each button, beginning with the leftmost (negative) button and moving to the rightmost (positive) button.  Simply change the values to what you want, save the file, then reopen tweenMachine.  The buttons should now have the new values that you set.

So what’s the down side?  Well, the biggest one is that you’re pretty much locked in to using seven buttons.  The MEL version was never designed to be flexible enough to support anything else. While it’s possible to alter the code to use more or less than seven buttons, it won’t be very elegant.  If other button quantities are desired, then I strongly suggest switching to the Python version, will is where I’m focusing all of my development time (such as it is).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.