3

enter image description here

My code for creating the animation if necessary

def testAnimation():

scn = bpy.context.scene
arm = bpy.data.armatures["Rig"]
rigobj = bpy.data.objects["Rig"]
scn.objects.active = rigobj
rigobj.select = True

bpy.ops.object.mode_set(mode = 'POSE')


boneSelect = bpy.context.object.data.bones['LBicep']
boneSelect.select = True

bpy.ops.transform.rotate(value=(0), axis=(1.0,1.0,1.0))
bpy.data.objects["Rig"].pose.bones['LBicep'].keyframe_insert(data_path='rotation_quaternion', frame = 0.0, group = "LBicep")

bpy.ops.transform.rotate(value=(math.pi*0.5), axis=(1.0,1.0,1.0))
bpy.data.objects["Rig"].pose.bones['LBicep'].keyframe_insert(data_path='rotation_quaternion', frame = 100.0, group = "LBicep")

bpy.ops.transform.rotate(value=(math.pi*0.5), axis=(1.0,1.0,1.0))
bpy.data.objects["Rig"].pose.bones['LBicep'].keyframe_insert(data_path='rotation_quaternion', frame = 200.0, group = "LBicep")

boneSelect.select = False
boneSelect = bpy.context.object.data.bones['LThigh']
boneSelect.select = True

bpy.ops.transform.rotate(value=(0), axis=(1.0,1.0,1.0))
bpy.data.objects["Rig"].pose.bones['LThigh'].keyframe_insert(data_path='rotation_quaternion', frame = 0.0, group = "LThigh")

bpy.ops.transform.rotate(value=(math.pi*0.5), axis=(1.0,1.0,1.0))
bpy.data.objects["Rig"].pose.bones['LThigh'].keyframe_insert(data_path='rotation_quaternion', frame = 150.0, group = "LThigh")

boneSelect.select = False
boneSelect = bpy.context.object.data.bones['RThigh']
boneSelect.select = True

bpy.ops.transform.translate(value=(0,0,0))
bpy.data.objects["Rig"].pose.bones['RThigh'].keyframe_insert(data_path='location', frame = 0.0, group = "RThigh")

bpy.ops.transform.translate(value=(0,10,0))
bpy.data.objects["Rig"].pose.bones['RThigh'].keyframe_insert(data_path='location', frame = 300.0, group = "RThigh")

bpy.ops.transform.translate(value=(0,-10,0))
bpy.data.objects["Rig"].pose.bones['RThigh'].keyframe_insert(data_path='location', frame = 700.0, group = "RThigh")


bpy.ops.object.mode_set(mode='OBJECT')
scn.update()
Garrett
  • 6,596
  • 6
  • 47
  • 75
The Intern
  • 137
  • 1
  • 9

1 Answers1

3

keyframe_insert() creates animation_data and an action if necessary, and makes it the new action of the active object.

Thus, you can simply access your object's action and change its name:

bpy.data.objects["Rig"].animation_data.action.name = "foobar"

Note that you shouldn't do this before any call to keyframe_insert(), as it would error out if there's either no animation_data or no action.

Refer to this question to learn about other approaches for animating things:

Python performance with Blender operators

CodeManX
  • 29,298
  • 3
  • 89
  • 128