Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save howiemnet/a3d7b9f283c9227f7fa2f355db89a5cf to your computer and use it in GitHub Desktop.
Save howiemnet/a3d7b9f283c9227f7fa2f355db89a5cf to your computer and use it in GitHub Desktop.
Houdini to AE camera animation clipboard exporter (now with Zoom! Woo!)
# Houdini to After Effects camera animation exporter
# This version: 7/11/2018, by Howard Matthews - h@howiem.net
# Copyright: CC-0 - use and abuse. Please pass on the knowledge.
# Note: there's no error-checking in this script, but it alters nothing within the Houdini scene, so it'll just
# fail with an error if you try running it without a camera selected. No harm done.
import hou
theNodes = hou.selectedNodes()
# 1. Put this code on a new button on a shelf in Houdini.
# 2. Select a camera (or camera switcher) and press the button.
# This script generates keyframe data for Position / Orientation / Zoom and copies it the system clipboard.
#
# ** IMPORTANT NOTE **
# In an ideal world, you could run this script, go to AE, create a camera, and hit Ctrl/Cmd-V and the animation data
# would be pasted straight in. HOWEVER, for some reason, Houdini's Python interpreter and Adobe's clipboard handler
# don't play nicely together. So there's an important additional step (at least on macOS - haven't tested on other OSs)
#
# 3. Open an empty text document, or a Stickies document - anywhere you can cut and paste text
# 4. Hit Paste [Cmd-V]
# 5. Select all text, and hit Copy [Cmd-A, Cmd-C]
#
# 6. Go to AE, first frame of your sequence, create a camera (if you haven't already), select it and hit Paste [Cmd-V].
# The camera animation data should now appear correctly in AE.
#
# 7. If your AE camera isn't matching up with what you've rendered in Houdini, check the AE camera is set up the same way:
# Go to the Camera settings in AE (select the camera, hit Shift-Cmd-Y) and check the resolution and the "film size" parameters.
# Houdini calls the film size "Aperture", just to be confusing. It's typically 41.4214mm. In AE's camera settings dialog, check
# that Units is set to millimetres, and Measure Film Size is set to Horizontally, then set the film size to whatever Houdini's
# Aperture setting is.
#
# 8. Send nudes.
h = theNodes[0]
startFrame = int(hou.playbar.playbackRange()[0])
endFrame = int(hou.playbar.playbackRange()[1])
scale = 100.0
myOutputString = "Adobe After Effects 8.0 Keyframe Data\n\n"
myOutputString = myOutputString + "\tUnits Per Second\t25\n"
myOutputString = myOutputString + "\tSource Width\t1920\n"
myOutputString = myOutputString + "\tSource Height\t1080\n"
myOutputString = myOutputString + "\tSource Pixel Aspect Ratio\t1\n"
myOutputString = myOutputString + "\tComp Pixel Aspect Ratio\t1\n"
# do the orientation:
myOutputString = myOutputString + "\nTransform\tOrientation\n"
myOutputString = myOutputString + "\tFrame\tX degrees\t\n"
for theFrame in range (startFrame,endFrame+1):
x = h.worldTransformAtTime(hou.frameToTime(theFrame))
xform = x.extractRotates('srt','zyx',hou.Vector3())
myOutputString = myOutputString + "\t"+str(theFrame)+"\t"+str(xform[0])+"\t"+str(-xform[1])+"\t"+str(-xform[2])+"\n"
# do the positions:
myOutputString = myOutputString + "\nTransform\tPosition\n"
myOutputString = myOutputString + "\tFrame\tX pixels\tY pixels\tZ pixels\n"
for theFrame in range (startFrame,endFrame+1):
x = h.worldTransformAtTime(hou.frameToTime(theFrame))
xform = x.extractTranslates('srt')
myOutputString = myOutputString + "\t"+str(theFrame)+"\t"+str(xform[0]*scale)+"\t"+str(-xform[1]*scale)+"\t"+str(-xform[2]*scale)+"\n"
# do the zoom:
myOutputString = myOutputString + "\nCamera Options\tZoom\n"
myOutputString = myOutputString + "\tFrame\tpixels\n"
for theFrame in range (startFrame,endFrame+1):
foc = h.parm("focal").evalAsFloatAtFrame(theFrame)
ape = h.parm("aperture").evalAsFloatAtFrame(theFrame)
wid = h.parm("resx").evalAsIntAtFrame(theFrame)
# After Effects uses zoom, rather than focal length:
zoom = (foc * wid) / ape
myOutputString = myOutputString + "\t"+str(theFrame)+"\t"+str(zoom)+"\n"
myOutputString = myOutputString + "\n\nEnd of Keyframe Data\n"
hou.ui.copyTextToClipboard(myOutputString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment