16
$\begingroup$

How can I add keyframes to custom properties with python? Usually, I can use the function

object.keyframe_insert(data_path="location")

but I couldn't find the right data_path of a custom property.

$\endgroup$
3
  • $\begingroup$ Thanks ideasman42, it works perfectly. Never used StackExchenge and it is difficult for me to not at least thank you for your efficient help. But I didn't found where is the best place to put this thanks... $\endgroup$
    – Salvatore
    Commented Oct 11, 2013 at 13:16
  • 1
    $\begingroup$ You can thank ideasman42 by accepting the answer. Just click the 'v' and it turns green :) $\endgroup$
    – jasperge
    Commented Feb 19, 2014 at 0:13
  • $\begingroup$ you are right, it's done. $\endgroup$
    – Salvatore
    Commented Feb 20, 2014 at 20:17

1 Answer 1

21
$\begingroup$

Keyframes on custom properties use Python's getitem/setitem syntax rather then getattr/setattr.

This matches python api, where you would access object.location as an attribute and object["prop"] for a custom property.

So you would need to write it like this:

object.keyframe_insert(data_path='["prop"]')

Note that you have to use " quotes, not ',
'["prop"]' can be written as "[\"prop\"]" too of course.

I think we have this documented, I'll have to double check though.

$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .