39#include "RNA_prototypes.hh"
59#define PYDOC_INSERTKEY_OPTIONS_LITERAL \
61 "'INSERTKEY_NEEDED', " \
62 "'INSERTKEY_VISUAL', " \
63 "'INSERTKEY_REPLACE', " \
64 "'INSERTKEY_AVAILABLE', " \
65 "'INSERTKEY_CYCLE_AWARE']"
66#define PYDOC_KEYTYPE_LITERAL \
79 const char *error_prefix,
81 const char **r_path_full,
83 bool *r_path_no_validate)
91 PyExc_TypeError,
"%.200s this struct has no data, cannot be animated", error_prefix);
101 else if (path_index != -1) {
102 PyErr_Format(PyExc_ValueError,
103 "%.200s path includes index, must be a separate argument",
109 PyErr_Format(PyExc_ValueError,
"%.200s path spans ID blocks", error_prefix, path);
118 if (prop ==
nullptr) {
119 if (r_path_no_validate) {
120 *r_path_no_validate =
true;
123 PyErr_Format(PyExc_TypeError,
"%.200s property \"%s\" not found", error_prefix, path);
127 if (r_path_no_validate) {
132 PyErr_Format(PyExc_TypeError,
"%.200s property \"%s\" not animatable", error_prefix, path);
137 if ((*r_index) == -1) {
141 PyErr_Format(PyExc_TypeError,
142 "%.200s index %d was given while property \"%s\" is not an array",
151 if ((*r_index) < -1 || (*r_index) >= array_len) {
152 PyErr_Format(PyExc_TypeError,
153 "%.200s index out of range \"%s\", given %d, array length is %d",
168 *r_path_full = path_full ?
BLI_strdup(path_full->c_str()) :
nullptr;
170 if (*r_path_full ==
nullptr) {
171 PyErr_Format(PyExc_TypeError,
"%.200s could not make path to \"%s\"", error_prefix, path);
180 const char *error_prefix,
182 const char **r_path_full,
192 const char *error_prefix,
194 const char **r_path_full)
204 PyErr_Format(PyExc_TypeError,
205 "%.200s could not make path for type %s",
222 const char *error_prefix,
224 const char **r_path_full,
227 bool path_unresolved =
false;
229 ptr, error_prefix, path, r_path_full, r_index, &path_unresolved) == -1)
231 if (path_unresolved ==
true) {
247 const char *parse_str,
248 const char *error_prefix,
250 const char **r_path_full,
253 const char **r_group_name,
257 static const char *kwlist[] = {
258 "data_path",
"index",
"frame",
"group",
"options",
"keytype",
nullptr};
259 PyObject *pyoptions =
nullptr;
260 std::optional<float> cfra;
261 char *keytype_name =
nullptr;
266 if (!PyArg_ParseTupleAndKeywords(args,
269 const_cast<char **
>(kwlist),
295 int keytype_as_int = 0;
310 if (cfra.has_value()) {
321 ".. method:: keyframe_insert(data_path, *, index=-1, frame=None, group=\"\", "
322 "options=set(), keytype='KEYFRAME')\n"
324 " Insert a keyframe on the property given, adding fcurves and animation data when "
327 " :param data_path: path to the property to key, analogous to the fcurve's data path.\n"
328 " :type data_path: str\n"
329 " :param index: array index of the property to key.\n"
330 " Defaults to -1 which will key all indices or a single channel if the property is not "
332 " :type index: int\n"
333 " :param frame: The frame on which the keyframe is inserted. "
334 "None (the default) uses ``bpy.context.scene.frame_current``.\n"
335 " :type frame: float | None\n"
336 " :param group: The name of the group the F-Curve should be added to if it doesn't exist "
338 " :type group: str\n"
339 " :param options: Optional set of flags:\n"
341 " - ``INSERTKEY_NEEDED`` Only insert keyframes where they're needed in the relevant "
343 " - ``INSERTKEY_VISUAL`` Insert keyframes based on 'visual transforms'.\n"
344 " - ``INSERTKEY_REPLACE`` Only replace already existing keyframes.\n"
345 " - ``INSERTKEY_AVAILABLE`` Only insert into already existing F-Curves.\n"
346 " - ``INSERTKEY_CYCLE_AWARE`` Take cyclic extrapolation into account "
347 "(Cycle-Aware Keying option).\n"
350 " :param keytype: Type of the key.\n"
353 " :return: Success of keyframe insertion.\n"
359 const char *path_full =
nullptr;
362 const char *group_name =
nullptr;
378 ":bpy_struct.keyframe_insert()",
379 "bpy_struct.keyframe_insert()",
406 if (self->
ptr->type == RNA_NlaStrip) {
414 const char *prop_name;
417 prop_name = strrchr(path_full,
'.');
418 if ((prop_name >= path_full) && (prop_name + 1 < path_full + strlen(path_full))) {
445 const std::optional<StringRefNull> channel_group = group_name ? std::optional(group_name) :
451 {{path_full, {},
index}},
457 if (success_count == 0) {
467 result = success_count != 0;
470 MEM_delete(path_full);
484 return PyBool_FromLong(
result);
488 ".. method:: keyframe_delete(data_path, *, index=-1, frame=None, group=\"\")\n"
490 " Remove a keyframe from this properties fcurve.\n"
492 " :param data_path: path to the property to remove a key, analogous to the fcurve's data "
494 " :type data_path: str\n"
495 " :param index: array index of the property to remove a key. "
496 "Defaults to -1 removing all indices or a single channel "
497 "if the property is not an array.\n"
498 " :type index: int\n"
499 " :param frame: The frame on which the keyframe is deleted. "
500 "None (the default) uses ``bpy.context.scene.frame_current``.\n"
501 " :type frame: float | None\n"
502 " :param group: The name of the group the F-Curve should be added to if it doesn't exist "
504 " :type group: str\n"
505 " :return: Success of keyframe deletion.\n"
510 const char *path_full =
nullptr;
513 const char *group_name =
nullptr;
527 ":bpy_struct.keyframe_delete()",
528 "bpy_struct.keyframe_delete()",
544 if (self->
ptr->type == RNA_NlaStrip) {
552 const char *prop_name;
555 prop_name = strrchr(path_full,
'.');
556 if ((prop_name >= path_full) && (prop_name + 1 < path_full + strlen(path_full))) {
572 "Not deleting keyframe for locked F-Curve for NLA Strip influence on %s - %s '%s'",
608 MEM_delete(path_full);
614 return PyBool_FromLong(
result);
618 ".. method:: driver_add(path, index=-1, /)\n"
620 " Adds driver(s) to the given property\n"
622 " :param path: path to the property to drive, analogous to the fcurve's data path.\n"
624 " :param index: array index of the property drive. "
625 "Defaults to -1 for all indices or a single channel if the property is not an array.\n"
626 " :type index: int\n"
627 " :return: The driver added or a list of drivers when index is -1.\n"
628 " :rtype: :class:`bpy.types.FCurve` | list[:class:`bpy.types.FCurve`]\n";
631 const char *path, *path_full;
636 if (!PyArg_ParseTuple(args,
648 &self->
ptr.value(),
"bpy_struct.driver_add():", path, &path_full, &
index) == -1)
653 PyObject *
ret =
nullptr;
666 PyErr_SetString(PyExc_TypeError,
667 "bpy_struct.driver_add(): failed because of an internal error");
670 ID *
id = self->
ptr->owner_id;
696 MEM_delete(path_full);
702 ".. method:: driver_remove(path, index=-1, /)\n"
704 " Remove driver(s) from the given property\n"
706 " :param path: path to the property to drive, analogous to the fcurve's data path.\n"
708 " :param index: array index of the property drive. "
709 "Defaults to -1 for all indices or a single channel if the property is not an array.\n"
710 " :type index: int\n"
711 " :return: Success of driver removal.\n"
715 const char *path, *path_full;
720 if (!PyArg_ParseTuple(args,
732 &self->
ptr.value(),
"bpy_struct.driver_remove():", path, &path_full, &
index) == -1)
744 if (path != path_full) {
745 MEM_delete(path_full);
757 return PyBool_FromLong(
result);
Functions to insert, delete or modify keyframes.
#define BLI_string_joinN(...)
#define BLI_string_join_by_sep_charN(...)
Read Blender memory allocation and freeing.
#define PYRNA_STRUCT_CHECK_OBJ(obj)
#define PYDOC_KEYTYPE_LITERAL
#define PYDOC_INSERTKEY_OPTIONS_LITERAL
int get_count(const SingleKeyingResult result) const
void generate_reports(ReportList *reports, eReportType report_level=RPT_ERROR)
CCL_NAMESPACE_BEGIN struct Options options
int delete_keyframe(Main *bmain, ReportList *reports, ID *id, const RNAPath &rna_path, float cfra)
Main Delete Key-Framing API call.
SingleKeyingResult insert_keyframe_direct(PointerRNA &ptr, PropertyRNA &prop, FCurve &fcu, float fcurve_frame, eBezTriple_KeyframeType keytype, eInsertKeyFlags flag)
Secondary Insert Key-framing API call.
void generate_single_keying_result_report(const SingleKeyingResult result, ReportList *reports)
CombinedKeyingResult insert_keyframes(Main *bmain, PointerRNA *struct_pointer, std::optional< StringRefNull > channel_group, const Span< RNAPath > rna_paths, std::optional< float > scene_frame, const AnimationEvalContext &anim_eval_context, eBezTriple_KeyframeType key_type, eInsertKeyFlags insert_key_flags)
Main key-frame insertion API.
const char * BKE_idtype_idcode_to_name(short idcode)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int ANIM_add_driver(ReportList *reports, ID *id, const char rna_path[], int array_index, short flag, eDriver_Types type)
Main Driver Management API calls.
PyObject * pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyObject *kw)
char pyrna_struct_keyframe_insert_doc[]
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
int pyrna_enum_bitfield_from_set(const EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix)
void BKE_reports_free(ReportList *reports)
void BKE_report_print_level_set(ReportList *reports, eReportType level)
PointerRNA RNA_id_pointer_create(ID *id)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
const char * RNA_property_identifier(const PropertyRNA *prop)
void BKE_reports_init(ReportList *reports, int flag)
void BPy_reports_write_stdout(const ReportList *reports, const char *header)
std::optional< std::string > RNA_path_from_ID_to_struct(const PointerRNA *ptr)
void BKE_fcurve_delete_key(FCurve *fcu, int index)
const EnumPropertyItem rna_enum_keying_flag_api_items[]
char pyrna_struct_keyframe_delete_doc[]
bool RNA_property_animateable(const PointerRNA *ptr, PropertyRNA *prop_orig)
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
AnimationEvalContext BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float eval_time) ATTR_WARN_UNUSED_RESULT
bool RNA_property_array_check(PropertyRNA *prop)
PyObject * pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyObject *kw)
AnimData * BKE_animdata_from_id(const ID *id)
static int pyrna_struct_keyframe_parse(PointerRNA *ptr, PyObject *args, PyObject *kw, const char *parse_str, const char *error_prefix, const char **r_path_full, int *r_index, float *r_cfra, const char **r_group_name, int *r_options, eBezTriple_KeyframeType *r_keytype)
bool BKE_fcurve_is_protected(const FCurve &fcu)
void BKE_fcurve_handles_recalc(FCurve &fcu)
void DEG_id_tag_update(ID *id, unsigned int flags)
struct bContext * BPY_context_get()
static int pyrna_struct_anim_args_parse_no_resolve(PointerRNA *ptr, const char *error_prefix, const char *path, const char **r_path_full)
const EnumPropertyItem rna_enum_beztriple_keyframe_type_items[]
char pyrna_struct_driver_remove_doc[]
bool ANIM_remove_driver(ID *id, const char rna_path[], int array_index)
Main Driver Management API calls.
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool RNA_struct_is_ID(const StructRNA *type)
PyObject * pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
const char * RNA_struct_identifier(const StructRNA *type)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
PyObject * pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
Main * CTX_data_main(const bContext *C)
char pyrna_struct_driver_add_doc[]
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
ID_Type GS(const char *name)
static int pyrna_struct_anim_args_parse(PointerRNA *ptr, const char *error_prefix, const char *path, const char **r_path_full, int *r_index)
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
static int pyrna_struct_anim_args_parse_no_resolve_fallback(PointerRNA *ptr, const char *error_prefix, const char *path, const char **r_path_full, int *r_index)
int BKE_fcurve_bezt_binarysearch_index(const BezTriple array[], float frame, int arraylen, bool *r_replace)
short BPy_reports_to_error(ReportList *reports, PyObject *exception, const bool clear)
FCurve * BKE_fcurve_find(ListBaseT< FCurve > *list, const char rna_path[], int array_index)
int pyrna_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value, const char *error_prefix)
@ RPT_PRINT_HANDLED_BY_OWNER
bool RNA_path_resolve_property_full(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index)
bool BKE_id_is_in_global_main(ID *id)
int PyC_ParseOptionalFloat(PyObject *o, void *p)
static int pyrna_struct_anim_args_parse_ex(PointerRNA *ptr, const char *error_prefix, const char *path, const char **r_path_full, int *r_index, bool *r_path_no_validate)
ListBaseT< FCurve > drivers
PyObject_HEAD std::optional< PointerRNA > ptr
ListBaseT< FCurve > fcurves