6

I would like to script keyframes for bevel modifier width (and many more later). Here is what I have so far. I've commented out the last line which doesn't work. When I type help(ao.keyframe_insert), I get :arg data_path: path to the property to key, analogous to the fcurve's data path. but that doesn't help me since I haven't use fcurves yet.

The first half of my question is "how to key the bevel width as I am trying in the example script?"

...and the second half is "where could I have looked this up?" or "how can I know in general what do write in keyframe_insert(data_path="" without asking a new question each time I want to key something?"

Thanks for your understanding!

import bpy
import numpy as np

frame_a, frame_b = 25, 35
sigma_a, sigma_b = 7, 10
n_frames = 60

if 1 == 1:
    bpy.ops.mesh.primitive_cube_add(radius=1, location=(0.0, 0.0, 2.0))
    bpy.ops.object.modifier_add(type='BEVEL')
    bpy.context.object.modifiers["Bevel"].width = 0.3
    bpy.context.object.modifiers["Bevel"].segments = 3

ao = bpy.context.active_object

bpy.context.scene.frame_end = n_frames

for i_frame in range(n_frames):
    a = np.exp(-(i_frame - frame_a)**2 / (2.*sigma_a**2))
    s = 1.0 + 0.3 * a
    bw = 1.0 * a
    ao.modifiers["Bevel"].width = bw
    ao.scale = (s, s, s)
    ao.keyframe_insert(data_path="scale", frame = i_frame + 1, index=-1)
    #ao.keyframe_insert(data_path="modifiers['Bevel'].width", frame = i_frame + 1, index=-1)
zeffii
  • 39,634
  • 9
  • 103
  • 186
uhoh
  • 2,667
  • 2
  • 27
  • 56
  • just switch the double quotes and the single quotes in the last line 'modifiers["Bevel"].width' – Chebhou Jul 27 '15 at 05:35
  • Wow! @Chebhou that's just what I needed - thanks! I'm wondering now should I just delete the question (it's really a non-question almost). – uhoh Jul 27 '15 at 05:42
  • I'll try @zeffii. That's a good answer to link to. But I don't know what an "outliner" is. – uhoh Jul 27 '15 at 05:53
  • Aha! got it. But I don't see how one could find 'modifiers["Bevel"].width' by looking at the outliner. – uhoh Jul 27 '15 at 06:08
  • @uhoh you can find it from the UI not the outliner exactly – Chebhou Jul 27 '15 at 06:15
  • OK up there at the top, the scrolling python narrative, right next to the left-handed smoke shifter. – uhoh Jul 27 '15 at 06:25
  • possible duplicate :( http://blender.stackexchange.com/questions/9363/is-there-a-list-for-keyframe-data-paths-in-blender/9368#9368 – zeffii Jul 27 '15 at 07:11

1 Answers1

8

To get the data_path of a UI element (property, icon..), rightclick it and select "Copy Data Path"

enter image description here

Wrapping the resulting data_path with double quotes is a legal python string representation (eg: "modifiers['Bevel'].width"), and arguably should be allowed. But the parser of properties favours 'modifiers["Bevel"].width', presumably to keep the string parsing to a minimal implementation.


The above will be able to compute most kinds of data_path, but if it fails you can

  • make a keyframe for the property
  • go to the Outliner (set to view Datablocks)
  • navigate to Actions -> (Object/Scenename)+Action -> F-Curve
  • See Data Path. (this is what the initial

    path to the property to key, analogous to the fcurve's data path

    refers to.)

zeffii
  • 39,634
  • 9
  • 103
  • 186
  • I see many good things I didn't know where there when I right click things like buttons, objects, or even sub-items in the outliner. But I never see "Copy data_path" I'm using 2.74 but do I need to turn something on? – uhoh Jul 27 '15 at 06:41
  • 1
    No, it's me. I just failed to click on things that were actually data. The image is extremely helpful! – uhoh Jul 27 '15 at 06:57