Skip to content

Instantly share code, notes, and snippets.

@tamask
Created December 7, 2011 15:58
Show Gist options
  • Save tamask/1443309 to your computer and use it in GitHub Desktop.
Save tamask/1443309 to your computer and use it in GitHub Desktop.
Export Blender Actions (.json)
import bpy
import json
json.encoder.c_make_encoder = None
json.encoder.FLOAT_REPR = lambda o: format(o, '.6f')
actions = []
for action in bpy.data.actions:
a = {
'name': action.name,
'range': list(action.frame_range),
'groups': [],
}
for group in action.groups:
g = {
'name': group.name,
'channels': [],
}
for fcurve in group.channels:
c = {
'path': fcurve.data_path,
'index': fcurve.array_index,
'points': [],
}
for point in fcurve.keyframe_points:
p = {
'a': list(point.handle_left),
'b': list(point.handle_right),
'co': list(point.co),
'lerp': point.interpolation.lower(),
}
c['points'].append(p)
g['channels'].append(c)
a['groups'].append(g)
actions.append(a)
print(json.dumps(actions))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment