Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
First attempt at getting AE camera data into Houdini (hacky woo)
# Ultra quick'n'hacky AE camera animation importer for Houdini.
# Create a new shelf, create a new tool, paste this into the script box.
#
# In AE, select the Orientation and/or Position keyframes, and Ctrl/Cmd-C them to the clipboard
# Open a new text file (Notepad or Textedit) and paste the clipboard contents in. There's your keyframes.
# Save the text file somewhere and amend the filename line below to suit
# In Houdini, create a camera (it's up to you to set the same zoom / aperture as the AE one).
# ... and run this script (well, press the shelf button you stuck this on)
import hou
# amend the next two lines as required
h = hou.node("/obj/cam1")
filename = "cameraKeyFrameData.txt"
state = "crap"
ignoreLine = False
with open (filename,"rU") as ff:
for theLine in ff:
elements = theLine.strip().split("\t")
ignoreLine = False
if len(elements) == 0:
state = "crap"
ignoreLine = True
else:
if elements.count("X degrees") > 0:
state = "orientation"
ignoreLine = True
if elements.count("X pixels") > 0:
state = "translate"
ignoreLine = True
if ignoreLine == False:
if len(elements) == 4:
theFrame = elements[0]
theXValue = elements[1]
theYValue = elements[2]
theZValue = elements[3]
if state == "translate":
print ("At frame "+theFrame+" translate to: "+theXValue)
setKey = hou.Keyframe()
setKey.setFrame(int(theFrame))
setKey.setValue(float(theXValue)*0.01)
testCh = hou.parm("obj/cam1/tx")
testCh.setKeyframe(setKey)
setKey = hou.Keyframe()
setKey.setFrame(int(theFrame))
setKey.setValue(-float(theYValue)*0.01)
testCh = hou.parm("obj/cam1/ty")
testCh.setKeyframe(setKey)
setKey = hou.Keyframe()
setKey.setFrame(int(theFrame))
setKey.setValue(-float(theZValue)*0.01)
testCh = hou.parm("obj/cam1/tz")
testCh.setKeyframe(setKey)
if state == "orientation":
print ("At frame "+theFrame+" orient to: "+theXValue)
setKey = hou.Keyframe()
setKey.setFrame(int(theFrame))
setKey.setValue(float(theXValue))
testCh = hou.parm("obj/cam1/rx")
testCh.setKeyframe(setKey)
setKey = hou.Keyframe()
setKey.setFrame(int(theFrame))
setKey.setValue(-float(theYValue))
testCh = hou.parm("obj/cam1/ry")
testCh.setKeyframe(setKey)
setKey = hou.Keyframe()
setKey.setFrame(int(theFrame))
setKey.setValue(-float(theZValue))
testCh = hou.parm("obj/cam1/rz")
testCh.setKeyframe(setKey)
@okplusplus

This comment has been minimized.

Copy link

@okplusplus okplusplus commented Nov 12, 2018

thanks a lot for the script + your process comment : very helpfull for a newbie !!!
++

@raytirat

This comment has been minimized.

Copy link

@raytirat raytirat commented Aug 21, 2019

Hi friend. With your permission, I have a little finalized your idea. Now you do not need to save the txt file. The camera animation is immediately copied from the buffer.

@raytirat

This comment has been minimized.

Copy link

@raytirat raytirat commented Aug 21, 2019

@howiemnet

This comment has been minimized.

Copy link
Owner Author

@howiemnet howiemnet commented Aug 23, 2019

Hi friend. With your permission, I have a little finalized your idea. Now you do not need to save the txt file. The camera animation is immediately copied from the buffer.

Heh - nice - but makes it platform dependent though. I'll try and get round to doing something a bit better. Tidiest solution would be to just grab the clipboard contents straight into a string and deal with it there.

@raytirat

This comment has been minimized.

Copy link

@raytirat raytirat commented Aug 23, 2019

Heh - nice - but makes it platform dependent though. I'll try and get round to doing something a bit better. Tidiest solution would be to just grab the clipboard contents straight into a string and deal with it there.

I didn’t quite manage to do this, because the buffer encoding adds extra tabs. But it will be very nice to look at your option

@dpreshit

This comment has been minimized.

Copy link

@dpreshit dpreshit commented Jan 17, 2020

Houdini shows me an error when i run this code, that is- "ValueError: invalid literal for int() with base 10: ''.
I found that replacing "setKey.setFrame(int(theFrame))" with "setKey.setFrame(int(float(theFrame)))" solves the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.