I want to write a script that changes the array modifier, and then inserts a keyframe for the new value.

I got it working, but it only does it on the first object. Unselecting all the objects, and then only the one I want to set it to also doesn't work.

Googling some more I found I should use obj.keyframe_insert, but what do I set the data_path to?

Here is an example of what I want to do

obj.modifiers['Array'].count = random.randint(1, 5)

I tried this first. bpy.ops.anim.keyframe_insert_menu(type='Available')
That works, but only sets it for the first object, the one that was selected; and it was iffy to start off with. I had to manually first set a keyframe, else it said 'Available' was not found.


When using keyframe_insert() you want to use it on the object that contains the value you wish to keyframe.

By "object" I am referring to python objects (as in "object" oriented programming) that are defined in a python class, not the visible 3d objects. In your example the object that has the value to be keyed is the modifier.

So to keyframe the count value in the array modifier you want to use -


You might also think of it as the class containing the property to be keyframed is the one that gets told to insert the keyframe.

As mentioned by pink vertex you can also go through the parent by using


Note the quotes " must be inside ' - swapping them around doesn't work.

  • $\begingroup$ Excellent. Thanks. And also, thanks for the tip on the quotes. Works Perfectly $\endgroup$ – Xuton Jul 24 '14 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.