2
$\begingroup$

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)
obj.keyframe_insert(data_path=???) 

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.

$\endgroup$
2
  • $\begingroup$ possible duplicate of Is there a list for Keyframe data_paths in Blender? $\endgroup$ Commented Jul 23, 2014 at 17:53
  • 1
    $\begingroup$ ... right click -> Copy Data Path yields modifiers["Array"].count - use '' quotation $\endgroup$ Commented Jul 23, 2014 at 19:00

1 Answer 1

4
$\begingroup$

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 -

obj.modifiers['Array'].keyframe_insert('count')

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

obj.keyframe_insert('modifiers["Array"].count')

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

$\endgroup$
1
  • $\begingroup$ Excellent. Thanks. And also, thanks for the tip on the quotes. Works Perfectly $\endgroup$ Commented Jul 24, 2014 at 8:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.