Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts

Monday, December 24, 2012

Pan Zoom Script [Animation]

Wouldn't it be nice if we could just zoom in and pan around in our shot cam without disturbing the camera?

One solution you might know about is Maya's Pan Zoom function:





In which case, you also know that this function sucks hard. Right. But we can build off this!


My script has two parts - in the first part, you will set a button to pan your camera view like you were holding down the spacebar in Photoshop or Flash. You need to set two different hotkey scripts to the same button, one for when the button is first pressed and one for when it's released.














The code for when it's pressed:

    global string $currentTool;
    $currentTool = `currentCtx`;
    PanZoomTool;

And when it's released:

    setToolTo $currentTool;

With this, you can hold down your hotkey and drag the mouse to around your camera view. When released, Maya automatically back to whatever tool you were using before you toggled the script.

We also want to be able to easily zoom in and out.

To zoom in, put this code on a hotkey (I used F1):

    panZoom -zoomRatio 0.9;

To zoom out, use this (I used F2):

    panZoom -zoomRatio 1.1;

To engage and disengage this function completely, all you have to do is toggle the Pan Zoom magnifying glass you see in the first image of this post.

Thursday, December 20, 2012

Copy Key Script [Animation]

This simple script I made copies your current key and pastes it onto the next key on the timeline. It replicates the 'middle mouse + drag + S' process we all hate. 



I'd recommend assigning it to an easily reached hotkey (I use 'Y').

Here's the code:

timeSliderCopyKey; //copies key
currentTime `findKeyframe -ts`; //finds next frame
timeSliderPasteKey false; //pastes onto frame

I use this script constantly when I animate. Many workflows, especially ones that involve keeping your shot in spline for most of the process, involve extensive use of copying and pasting keys to 'bookend' your pose as if it were in stepped tangents. To me, this process is too laborious to allow for the experimentation you want be doing during blocking. But with this script on a hotkey, this workflow is fast and adaptable - especially when combined with your 'select all' hotkey. And if that's not a workflow that appeals to you, this script will  probably stillprove worthy of your keyboard real estate.


If you want the code to copy a key to the previous key, here's that too:

timeSliderCopyKey;
PreviousKey;
timeSliderPasteKey false

Back to Basics: Hotkeys

Hotkeys are old news for most, but we're going to be posting a lot of scripts so you should know how to use them.


The most basic way to run a script is to copy it into your script editor and press enter:





This is okay, but often you'll want to assign a script to a hotkey on your keyboard so you can easily repeat it. Access the hotkey editor through Window > Settings/Preferences > Hotkey Editor:

 

Once you have the Hotkey Editor open, follow the following instructions to make your hotkey:




1. Scroll down to the 'User' category in the leftmost pane.
2. Click the 'New' button on the far right to make your command. Note that you don't have to assign it to a hotkey immediately.
3. Give it a good name. Or a bad one
4. Copy your command into the command field.
5. Click the accept button.
6. Assign a hotkey to your command. Type the key in the 'Key" field, choose any Control/Option/Command modifier you want, and press Assign. It will overwrite any existing hotkey applied to that key.
7. Click 'Save' on the bottom of the window.

You can also middle mouse drag the actual mel/python code of a script up to a shelf to make a little shelf button.

This stuff is dull and setting it all up at first can be intimidating. But really it's not too tricky and will be well worth your time to figure out.