# Insert Animation Keyframe works, but messes up all other Actions

I've written a small script as follows:

Requirements

Manual Part: I manually select a specific Action in Dopesheet -> Action Editor. (Note that these actions will have only two keyframes, at 1 and at 50, with identical poses).

After this I manually select specific bones to which the script below should apply.

Script Part: Then run the script to do the following:

1. Loop through all keyframes and add small random rotations to all the bones I've selected in the manual part.
2. Insert new keyframes which contain these random rotations

Actual Script:

import bpy
import random
import math

# User Settings
keyframe_insert_interval = 5
rand_rotation_deg_max = 0.25

# Get scene stuff
c = bpy.context
s = c.scene

# Get frames start and end
frame_start = s.frame_start
frame_end = s.frame_end
bones_to_rotate = c.selected_pose_bones

for i in range(frame_start + keyframe_insert_interval, frame_end, keyframe_insert_interval):
s.frame_current = i

# Iterate through all bones
for j in range(0, len(bones_to_rotate)):
# Current Bone
bone_curr = bones_to_rotate[j]

# Set rotation mode
bone_curr.rotation_mode = 'XYZ'

# Get next random rotation add
new_rand_x = random.uniform(-1.0 * rand_rotation_deg_max, rand_rotation_deg_max)
new_rand_y = random.uniform(-1.0 * rand_rotation_deg_max, rand_rotation_deg_max)
new_rand_z = random.uniform(-1.0 * rand_rotation_deg_max, rand_rotation_deg_max)

# Placeholder - might want to add some other randomness ,so creating vars
new_x = new_rand_x
new_y = new_rand_y
new_z = new_rand_z

# Rotate

# Tried all of these, none seem to work correctly
#bpy.data.actions[6].keyframe_insert(data_path="rotation_euler",frame=i)
bone_curr.keyframe_insert(data_path="rotation_euler",frame=i)
#bpy.ops.anim.keyframe_insert(type='LocRotScale')


Problem

The script works perfectly on the currently selected Action, but it messes up all the other actions. For some reason it applies the random rotations to all the other (unselected) Actions as well.

I'm sure I'm doing something systematically wrong, but cannot figure out what it is, and some help would be greatly appreciated!

Thanks very much, staticvoidlol

• this is working fine for me ,i have armature with multiple actions (empty) any other steps i'm messing ? – Chebhou Apr 23 '15 at 2:08