Vincent Touache - Character TD
/tutos/23_maya_trick_frameSelected/content.php
data=================:ArrayMaya trick - Hack the 'F' behavior

Table of Contents

  1. How to intercept Maya's frameSelected behavior



How to intercept Maya's frameSelected behavior

Recently, I had to implement my own logic of framing the selected object, where "f" would actually not frame the current selection, but something else connected to my selected object. Having an action that triggers a focus in a tool is pretty straightforward, you just call the viewFit command. But in my case, I wanted to have something seamless for animators. One way to approach it is to override the corresponding MEL proc, called by Maya, similar to what you do when you override right clicks with dagMenuProc.mel.

What you're looking for is a file called "fitPanel.mel". Mine is in /Applications/Autodesk/maya2024/Maya.app/Contents/scripts/others/fitPanel.mel, but you can easily find yours by running "whatIs fitPanel" in a MEL scriptEditor tab within Maya. Once you have your fitPanel.mel file open (you don't want to have to reinstall maya if you screw that file up, so make a backup), all you have to do is to insert your hack logic wherever you want. In my case, I had a specific viewport. But you could also do something based on your custom viewport name, the type of widget (outliner, graph editor, node editor, etc...), and so on. E.g.:

    ...
    if ($panel != "") {
        string $type = `getPanel -to $panel`;

        // ------ this is what I added ------
        if ($type == "my_custom_panel"){
            python("import my_module;my_module.do_something_special");
        }
        // ---------------------------------- 
        else if ($type == "modelPanel") 
        {
            ...

            

Finally, you just source your script either directly inside your maya session with "source path/to/fitPanel.mel", or you automatically launch it on maya startup.
Next time you'll hit "F", it will go through this file and your hook will catch it