Import “Mocha-AE” tracks to Nuke via Python

July 27, 2012

This is an update to my original post Convert “Mocha for AE” tracking data to Shake / Nuke nodes

***UPDATE***

I must emphasise that this was a test project for me to learn Python for Nuke – what the script is doing is probably in violation of the Mocha end user agreement. As I stated in my original post, the PHP version of the script was a one-off fix for a small job where the facility I was working in did not have a full Mocha licence and I needed a quick solution. I have since been working at bigger facilities that use full Mocha Pro licences, so have not needed to use the script.
Mocha Pro is the current supported way to get Mocha tracking data to Nuke – please don’t use my hacky script as a stand-in for this great piece of software.

A while ago I wrote a PHP script that takes the tracking data generated by Mocha-AE (the version of Mocha that comes bundled with After Effects) and converts it to Shake and Nuke nodes.

Well I had a quiet spell over the last couple of days and thought I would use it to learn Python. My first project was to re-create my Mocha-AE import script, but have it run natively within Nuke. This would force me to cover some Python basics such as importing files, parsing strings to generate arrays etc. as well as some Nuke specific functions like creating nodes and adding animation data. I also wanted to extend the script to create a CornerPin node as well as a Tracker node.

I was surprised how quickly this came together. There are some great online resources such as The Foundry’s website and Nukepedia, and I find Python quite a simple and logical language to learn.

So here is my code. I will give the disclaimer that it is literally the first thing I have ever written in Python, so I’m sure that it could be more efficient. If you know any ways to improve its functionality, please leave comments below.

As with the previous version, this assumes you have used the “After Effects Corner Pin [corner pin only, supports RG Warp and mochaImport] (*.txt) “
export method from Mocha-AE.

You can wrap this up into a menu item to give your Nuke install permanent access to it as a function (I may update this post as to how, but until then try here), or the simplest way to run it is to just copy the code below and run it via Nuke’s Script Editor panel.

Here is the GitHub link for the code – just select the text, copy it then, then paste it into Nuke’s Script Editor panel.

4 Responses to "Import “Mocha-AE” tracks to Nuke via Python"

Awesome!!! Thanks so much for sharing this Richard!

Henrique Reginato says: October 1, 2015 at 8:17 pm

Hey man, this is awesome and i have been using it for quite a while… But I’m having trouble wrapping it up into a Menu item…
have you figured out how ??
The closest I got was still launching the tool together with Nuke and the menu I created was unresponsive…

Raymond says: July 9, 2017 at 1:23 pm

Hi Richard… I’m not sure but I believe I used to work with you in dneg where we used your script and incorporate it into dneg Singapore’s nuke.

Anyhow, are you familiar with Natron? It’s like a clone version of nuke but difference is it’s free. I was wondering if it’s possible to have a mocha ae python script for that compositing software.

Hi Raymond
I haven’t used Natron, but understand that you can run Python scripts within it. You should be able to modify this script fairly easily. You would just need to replace the createNukeCornerPinNode() and createNukeTrackerNode() functions with something that creates an equivalent Natron node. The parsing of incoming text using convertIncomingData() should still work the same.
Regards

Leave a comment to Raymond Cancel reply

required