Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2012-12-23 17:58:42 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2012-12-23 17:58:42 +0400
commit789b2acd772c2856a09017972e9cc7278f60c4ab (patch)
tree757db2f996ce41ca3407bd64f9fcdf10f65ba41d
parent851cb9b3455369fb9796e3c27e05e5e88f4f36b0 (diff)
Add keying "options" parameter to keyframe_insert() bpy_rna function, so now you can enable 'INSERTKEY_NEEDED', 'INSERTKEY_VISUAL' and/or 'INSERTKEY_XYZ_TO_RGB' when you directly key some property from python script (previously those options were only available through keyingsets).
Thanks to Campbell for review!
-rw-r--r--source/blender/makesrna/RNA_enum_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_animation.c25
-rw-r--r--source/blender/python/intern/bpy_rna_anim.c39
3 files changed, 44 insertions, 21 deletions
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index 0f9a00de7b6..9d08cf2d364 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -70,6 +70,7 @@ extern EnumPropertyItem keyframe_handle_type_items[];
extern EnumPropertyItem keyblock_type_items[];
extern EnumPropertyItem keyingset_path_grouping_items[];
+extern EnumPropertyItem keying_flag_items[];
extern EnumPropertyItem keyframe_paste_offset_items[];
extern EnumPropertyItem keyframe_paste_merge_items[];
diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c
index 7229dddf6d6..402d05a20b6 100644
--- a/source/blender/makesrna/intern/rna_animation.c
+++ b/source/blender/makesrna/intern/rna_animation.c
@@ -52,6 +52,20 @@ EnumPropertyItem keyingset_path_grouping_items[] = {
{0, NULL, 0, NULL, NULL}
};
+/* It would be cool to get rid of this 'INSERTKEY_' prefix in 'py strings' values, but it would break existing
+ * exported keyingset... :/
+ */
+EnumPropertyItem keying_flag_items[] = {
+ {INSERTKEY_NEEDED, "INSERTKEY_NEEDED", 0, "Only Needed",
+ "Only insert keyframes where they're needed in the relevant F-Curves"},
+ {INSERTKEY_MATRIX, "INSERTKEY_VISUAL", 0, "Visual Keying",
+ "Insert keyframes based on 'visual transforms'"},
+ {INSERTKEY_XYZ2RGB, "INSERTKEY_XYZ_TO_RGB", 0, "XYZ=RGB Colors",
+ "Color for newly added transformation F-Curves (Location, Rotation, Scale) "
+ "and also Color is based on the transform axis"},
+ {0, NULL, 0, NULL, NULL}
+};
+
#ifdef RNA_RUNTIME
#include "BLI_math_base.h"
@@ -518,17 +532,6 @@ static void rna_def_common_keying_flags(StructRNA *srna, short UNUSED(reg))
{
PropertyRNA *prop;
- static EnumPropertyItem keying_flag_items[] = {
- {INSERTKEY_NEEDED, "INSERTKEY_NEEDED", 0, "Only Needed",
- "Only insert keyframes where they're needed in the relevant F-Curves"},
- {INSERTKEY_MATRIX, "INSERTKEY_VISUAL", 0, "Visual Keying",
- "Insert keyframes based on 'visual transforms'"},
- {INSERTKEY_XYZ2RGB, "INSERTKEY_XYZ_TO_RGB", 0, "XYZ=RGB Colors",
- "Color for newly added transformation F-Curves (Location, Rotation, Scale) "
- "and also Color is based on the transform axis"},
- {0, NULL, 0, NULL, NULL}
- };
-
prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "keyingflag");
RNA_def_property_enum_items(prop, keying_flag_items);
diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c
index 69839514a12..cacae8fd184 100644
--- a/source/blender/python/intern/bpy_rna_anim.c
+++ b/source/blender/python/intern/bpy_rna_anim.c
@@ -44,6 +44,7 @@
#include "BKE_fcurve.h"
#include "RNA_access.h"
+#include "RNA_enum_types.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -147,14 +148,17 @@ static int pyrna_struct_anim_args_parse(
/* internal use for insert and delete */
static int pyrna_struct_keyframe_parse(
PointerRNA *ptr, PyObject *args, PyObject *kw, const char *parse_str, const char *error_prefix,
- const char **path_full, int *index, float *cfra, const char **group_name) /* return values */
+ const char **path_full, int *index, float *cfra, const char **group_name, int *options) /* return values */
{
- static const char *kwlist[] = {"data_path", "index", "frame", "group", NULL};
+ static const char *kwlist[] = {"data_path", "index", "frame", "group", "options", NULL};
+ PyObject *pyoptions = NULL;
const char *path;
- /* note, parse_str MUST start with 's|ifs' */
- if (!PyArg_ParseTupleAndKeywords(args, kw, parse_str, (char **)kwlist, &path, index, cfra, group_name))
+ /* note, parse_str MUST start with 's|ifsO!' */
+ if (!PyArg_ParseTupleAndKeywords(args, kw, parse_str, (char **)kwlist, &path, index, cfra, group_name,
+ &PySet_Type, &pyoptions)) {
return -1;
+ }
if (pyrna_struct_anim_args_parse(ptr, error_prefix, path, path_full, index) < 0)
return -1;
@@ -162,6 +166,13 @@ static int pyrna_struct_keyframe_parse(
if (*cfra == FLT_MAX)
*cfra = CTX_data_scene(BPy_GetContext())->r.cfra;
+ /* flag may be null (no option currently for remove keyframes e.g.). */
+ if (pyrna_struct_anim_args_parse(ptr, error_prefix, path, path_full, index) < 0)
+ return -1;
+
+ if (pyoptions && options && (pyrna_set_to_enum_bitfield(keying_flag_items, pyoptions, options, error_prefix) < 0))
+ return -1;
+
return 0; /* success */
}
@@ -172,12 +183,19 @@ char pyrna_struct_keyframe_insert_doc[] =
"\n"
" :arg data_path: path to the property to key, analogous to the fcurve's data path.\n"
" :type data_path: string\n"
-" :arg index: array index of the property to key. Defaults to -1 which will key all indices or a single channel if the property is not an array.\n"
+" :arg index: array index of the property to key. Defaults to -1 which will key all indices or a single channel "
+ "if the property is not an array.\n"
" :type index: int\n"
" :arg frame: The frame on which the keyframe is inserted, defaulting to the current frame.\n"
" :type frame: float\n"
" :arg group: The name of the group the F-Curve should be added to if it doesn't exist yet.\n"
" :type group: str\n"
+" :arg options: Some optional flags:\n"
+" 'NEEDED': Only insert keyframes where they're needed in the relevant F-Curves.\n"
+" 'VISUAL': Insert keyframes based on 'visual transforms'.\n"
+" 'XYZ_TO_RGB': Color for newly added transformation F-Curves (Location, Rotation, Scale) "
+ "and also Color is based on the transform axis.\n"
+" :type flag: set\n"
" :return: Success of keyframe insertion.\n"
" :rtype: boolean\n"
;
@@ -188,12 +206,13 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
int index = -1;
float cfra = FLT_MAX;
const char *group_name = NULL;
+ int options = 0;
PYRNA_STRUCT_CHECK_OBJ(self);
if (pyrna_struct_keyframe_parse(&self->ptr, args, kw,
- "s|ifs:bpy_struct.keyframe_insert()", "bpy_struct.keyframe_insert()",
- &path_full, &index, &cfra, &group_name) == -1)
+ "s|ifsO!:bpy_struct.keyframe_insert()", "bpy_struct.keyframe_insert()",
+ &path_full, &index, &cfra, &group_name, &options) == -1)
{
return NULL;
}
@@ -203,7 +222,7 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
BKE_reports_init(&reports, RPT_STORE);
- result = insert_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
+ result = insert_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, options);
MEM_freeN((void *)path_full);
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
@@ -240,9 +259,9 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
PYRNA_STRUCT_CHECK_OBJ(self);
if (pyrna_struct_keyframe_parse(&self->ptr, args, kw,
- "s|ifs:bpy_struct.keyframe_delete()",
+ "s|ifsO!:bpy_struct.keyframe_delete()",
"bpy_struct.keyframe_insert()",
- &path_full, &index, &cfra, &group_name) == -1)
+ &path_full, &index, &cfra, &group_name, NULL) == -1)
{
return NULL;
}