2011-03-02 04:51:43 +00:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file blender/python/intern/bpy_rna_anim.c
|
|
|
|
* \ingroup pythonintern
|
2011-11-05 08:21:12 +00:00
|
|
|
*
|
|
|
|
* This file defines the animation related methods used in bpy_rna.c
|
2011-03-02 04:51:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
#include <float.h> /* FLT_MIN/MAX */
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2012-02-26 23:59:08 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2011-03-02 04:51:43 +00:00
|
|
|
#include "BLI_string.h"
|
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_anim_types.h"
|
|
|
|
#include "ED_keyframing.h"
|
|
|
|
|
|
|
|
#include "BKE_report.h"
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_animsys.h"
|
|
|
|
#include "BKE_fcurve.h"
|
|
|
|
|
2011-03-02 06:47:08 +00:00
|
|
|
#include "RNA_access.h"
|
2012-12-23 13:58:42 +00:00
|
|
|
#include "RNA_enum_types.h"
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2011-05-08 05:41:57 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
2011-03-02 04:51:43 +00:00
|
|
|
#include "bpy_rna.h"
|
|
|
|
#include "bpy_util.h"
|
2011-04-03 10:04:16 +00:00
|
|
|
#include "bpy_rna_anim.h"
|
2011-03-02 04:51:43 +00:00
|
|
|
|
|
|
|
/* for keyframes and drivers */
|
2011-11-26 15:18:30 +00:00
|
|
|
static int pyrna_struct_anim_args_parse(
|
|
|
|
PointerRNA *ptr, const char *error_prefix, const char *path,
|
|
|
|
const char **path_full, int *index)
|
2011-03-02 04:51:43 +00:00
|
|
|
{
|
2014-01-28 03:52:21 +11:00
|
|
|
const bool is_idbase = RNA_struct_is_ID(ptr->type);
|
2011-03-02 04:51:43 +00:00
|
|
|
PropertyRNA *prop;
|
|
|
|
PointerRNA r_ptr;
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
if (ptr->data == NULL) {
|
2011-04-30 13:58:31 +00:00
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
"%.200s this struct has no data, can't be animated",
|
|
|
|
error_prefix);
|
2011-03-02 04:51:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* full paths can only be given from ID base */
|
2011-10-13 01:29:08 +00:00
|
|
|
if (is_idbase) {
|
2011-12-26 12:26:11 +00:00
|
|
|
int r_index = -1;
|
Bugfix [#34836] Crash when driver variable has path == 'data'
Most of the places which relied on RNA_path_resolve() did so believing that if
it returned true, that it had found a valid property, and that the returned
pointer+property combination would be what the path referred to. However, it
turns out that if the property at the end of the path turns out to be a
"pointer" property (e.g. "data" for Object.data), this would automatically
become the pointer part, while the prop part would be set to null. Hence, if a
user accidentally (or otherwise) specifies a path for the single-property driver
variable type like this, then Blender would crash.
This commit introduces two convenience functions - RNA_path_resolve_property()
and RNA_path_resolve_property_full() - which mirror/wrap the existing
RNA_path_resolve() functions. The only difference though is that these include a
check to ensure that what was found from resolving the path was in fact a
property (they only return true iff this is the case), and make it explicitly
clear in the name that this is what they will do so that there's no further
confusion. It is possible to do without these wrapper functions by doing these
checks inline, but the few cases that had been patched already were pretty
hideous looking specimens. Using these just make it clearer and simpler for all.
I've also beefed up the docs on these a bit, and changed these to using bools.
2013-04-22 13:22:07 +00:00
|
|
|
if (RNA_path_resolve_property_full(ptr, path, &r_ptr, &prop, &r_index) == false) {
|
2011-12-26 12:26:11 +00:00
|
|
|
prop = NULL;
|
2011-03-02 04:51:43 +00:00
|
|
|
}
|
2011-10-13 01:29:08 +00:00
|
|
|
else if (r_index != -1) {
|
2011-04-30 13:58:31 +00:00
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"%.200s path includes index, must be a separate argument",
|
|
|
|
error_prefix, path);
|
2011-03-02 04:51:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-10-13 01:29:08 +00:00
|
|
|
else if (ptr->id.data != r_ptr.id.data) {
|
2011-04-30 13:58:31 +00:00
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"%.200s path spans ID blocks",
|
|
|
|
error_prefix, path);
|
2011-03-02 04:51:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-12-26 12:26:11 +00:00
|
|
|
prop = RNA_struct_find_property(ptr, path);
|
|
|
|
r_ptr = *ptr;
|
2011-03-02 04:51:43 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
if (prop == NULL) {
|
2011-04-30 13:58:31 +00:00
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
"%.200s property \"%s\" not found",
|
|
|
|
error_prefix, path);
|
2011-03-02 04:51:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!RNA_property_animateable(&r_ptr, prop)) {
|
2011-04-30 13:58:31 +00:00
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
"%.200s property \"%s\" not animatable",
|
|
|
|
error_prefix, path);
|
2011-03-02 04:51:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (RNA_property_array_check(prop) == 0) {
|
|
|
|
if ((*index) == -1) {
|
2011-12-26 12:26:11 +00:00
|
|
|
*index = 0;
|
2011-03-02 04:51:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-04-30 13:58:31 +00:00
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
"%.200s index %d was given while property \"%s\" is not an array",
|
|
|
|
error_prefix, *index, path);
|
2011-03-02 04:51:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-12-26 12:26:11 +00:00
|
|
|
int array_len = RNA_property_array_length(&r_ptr, prop);
|
2011-10-13 01:29:08 +00:00
|
|
|
if ((*index) < -1 || (*index) >= array_len) {
|
2011-04-30 13:58:31 +00:00
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
"%.200s index out of range \"%s\", given %d, array length is %d",
|
|
|
|
error_prefix, path, *index, array_len);
|
2011-03-02 04:51:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (is_idbase) {
|
2011-12-26 12:26:11 +00:00
|
|
|
*path_full = BLI_strdup(path);
|
2011-03-02 04:51:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-12-26 12:26:11 +00:00
|
|
|
*path_full = RNA_path_from_ID_to_property(&r_ptr, prop);
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
if (*path_full == NULL) {
|
2011-04-30 13:58:31 +00:00
|
|
|
PyErr_Format(PyExc_TypeError,
|
|
|
|
"%.200s could not make path to \"%s\"",
|
|
|
|
error_prefix, path);
|
2011-03-02 04:51:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* internal use for insert and delete */
|
2011-11-26 15:18:30 +00:00
|
|
|
static int pyrna_struct_keyframe_parse(
|
2012-03-26 20:41:54 +00:00
|
|
|
PointerRNA *ptr, PyObject *args, PyObject *kw, const char *parse_str, const char *error_prefix,
|
2012-12-23 13:58:42 +00:00
|
|
|
const char **path_full, int *index, float *cfra, const char **group_name, int *options) /* return values */
|
2011-03-02 04:51:43 +00:00
|
|
|
{
|
2012-12-23 13:58:42 +00:00
|
|
|
static const char *kwlist[] = {"data_path", "index", "frame", "group", "options", NULL};
|
|
|
|
PyObject *pyoptions = NULL;
|
2011-03-02 04:51:43 +00:00
|
|
|
const char *path;
|
|
|
|
|
2012-12-23 13:58:42 +00:00
|
|
|
/* note, parse_str MUST start with 's|ifsO!' */
|
|
|
|
if (!PyArg_ParseTupleAndKeywords(args, kw, parse_str, (char **)kwlist, &path, index, cfra, group_name,
|
2013-03-01 14:47:06 +00:00
|
|
|
&PySet_Type, &pyoptions))
|
|
|
|
{
|
2011-03-02 04:51:43 +00:00
|
|
|
return -1;
|
2012-12-23 13:58:42 +00:00
|
|
|
}
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2013-01-10 15:22:19 +00:00
|
|
|
if (pyrna_struct_anim_args_parse(ptr, error_prefix, path, path_full, index) == -1)
|
2011-03-02 04:51:43 +00:00
|
|
|
return -1;
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
if (*cfra == FLT_MAX)
|
|
|
|
*cfra = CTX_data_scene(BPy_GetContext())->r.cfra;
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2012-12-23 13:58:42 +00:00
|
|
|
/* flag may be null (no option currently for remove keyframes e.g.). */
|
2014-04-29 07:34:09 +10:00
|
|
|
if (options) {
|
|
|
|
if (pyoptions && (pyrna_set_to_enum_bitfield(keying_flag_items, pyoptions, options, error_prefix) == -1)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*options |= INSERTKEY_NO_USERPREF;
|
|
|
|
}
|
2012-12-23 13:58:42 +00:00
|
|
|
|
2011-03-02 04:51:43 +00:00
|
|
|
return 0; /* success */
|
|
|
|
}
|
|
|
|
|
|
|
|
char pyrna_struct_keyframe_insert_doc[] =
|
|
|
|
".. method:: keyframe_insert(data_path, index=-1, frame=bpy.context.scene.frame_current, group=\"\")\n"
|
|
|
|
"\n"
|
|
|
|
" Insert a keyframe on the property given, adding fcurves and animation data when necessary.\n"
|
|
|
|
"\n"
|
|
|
|
" :arg data_path: path to the property to key, analogous to the fcurve's data path.\n"
|
|
|
|
" :type data_path: string\n"
|
2012-12-23 13:58:42 +00:00
|
|
|
" :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"
|
2011-03-02 04:51:43 +00:00
|
|
|
" :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"
|
2012-12-23 13:58:42 +00:00
|
|
|
" :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"
|
2011-03-02 04:51:43 +00:00
|
|
|
" :return: Success of keyframe insertion.\n"
|
|
|
|
" :rtype: boolean\n"
|
|
|
|
;
|
|
|
|
PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyObject *kw)
|
|
|
|
{
|
|
|
|
/* args, pyrna_struct_keyframe_parse handles these */
|
2011-12-26 12:26:11 +00:00
|
|
|
const char *path_full = NULL;
|
|
|
|
int index = -1;
|
|
|
|
float cfra = FLT_MAX;
|
|
|
|
const char *group_name = NULL;
|
2012-12-23 13:58:42 +00:00
|
|
|
int options = 0;
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2011-10-10 07:10:53 +00:00
|
|
|
PYRNA_STRUCT_CHECK_OBJ(self);
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (pyrna_struct_keyframe_parse(&self->ptr, args, kw,
|
2012-12-23 13:58:42 +00:00
|
|
|
"s|ifsO!:bpy_struct.keyframe_insert()", "bpy_struct.keyframe_insert()",
|
|
|
|
&path_full, &index, &cfra, &group_name, &options) == -1)
|
2011-04-30 13:58:31 +00:00
|
|
|
{
|
2011-03-02 04:51:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
short result;
|
|
|
|
ReportList reports;
|
|
|
|
|
|
|
|
BKE_reports_init(&reports, RPT_STORE);
|
|
|
|
|
2012-12-23 13:58:42 +00:00
|
|
|
result = insert_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, options);
|
2011-03-02 04:51:43 +00:00
|
|
|
MEM_freeN((void *)path_full);
|
|
|
|
|
2013-01-07 05:26:12 +00:00
|
|
|
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)
|
2011-03-02 04:51:43 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return PyBool_FromLong(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char pyrna_struct_keyframe_delete_doc[] =
|
|
|
|
".. method:: keyframe_delete(data_path, index=-1, frame=bpy.context.scene.frame_current, group=\"\")\n"
|
|
|
|
"\n"
|
|
|
|
" Remove a keyframe from this properties fcurve.\n"
|
|
|
|
"\n"
|
|
|
|
" :arg data_path: path to the property to remove a key, analogous to the fcurve's data path.\n"
|
|
|
|
" :type data_path: string\n"
|
|
|
|
" :arg index: array index of the property to remove a key. Defaults to -1 removing 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 deleted, 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"
|
|
|
|
" :return: Success of keyframe deleation.\n"
|
|
|
|
" :rtype: boolean\n"
|
|
|
|
;
|
|
|
|
PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyObject *kw)
|
|
|
|
{
|
|
|
|
/* args, pyrna_struct_keyframe_parse handles these */
|
2011-12-26 12:26:11 +00:00
|
|
|
const char *path_full = NULL;
|
|
|
|
int index = -1;
|
|
|
|
float cfra = FLT_MAX;
|
|
|
|
const char *group_name = NULL;
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2011-10-10 07:10:53 +00:00
|
|
|
PYRNA_STRUCT_CHECK_OBJ(self);
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (pyrna_struct_keyframe_parse(&self->ptr, args, kw,
|
2012-12-23 13:58:42 +00:00
|
|
|
"s|ifsO!:bpy_struct.keyframe_delete()",
|
2012-03-26 20:41:54 +00:00
|
|
|
"bpy_struct.keyframe_insert()",
|
2012-12-23 13:58:42 +00:00
|
|
|
&path_full, &index, &cfra, &group_name, NULL) == -1)
|
2011-04-30 13:58:31 +00:00
|
|
|
{
|
2011-03-02 04:51:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
short result;
|
|
|
|
ReportList reports;
|
|
|
|
|
|
|
|
BKE_reports_init(&reports, RPT_STORE);
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
result = delete_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
|
2011-03-02 04:51:43 +00:00
|
|
|
MEM_freeN((void *)path_full);
|
|
|
|
|
2013-01-07 05:26:12 +00:00
|
|
|
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)
|
2011-03-02 04:51:43 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return PyBool_FromLong(result);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
char pyrna_struct_driver_add_doc[] =
|
|
|
|
".. method:: driver_add(path, index=-1)\n"
|
|
|
|
"\n"
|
|
|
|
" Adds driver(s) to the given property\n"
|
|
|
|
"\n"
|
|
|
|
" :arg path: path to the property to drive, analogous to the fcurve's data path.\n"
|
|
|
|
" :type path: string\n"
|
|
|
|
" :arg index: array index of the property drive. Defaults to -1 for all indices or a single channel if the property is not an array.\n"
|
|
|
|
" :type index: int\n"
|
|
|
|
" :return: The driver(s) added.\n"
|
2011-10-09 02:24:51 +00:00
|
|
|
" :rtype: :class:`bpy.types.FCurve` or list if index is -1 with an array property.\n"
|
2011-03-02 04:51:43 +00:00
|
|
|
;
|
|
|
|
PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
|
|
|
|
{
|
|
|
|
const char *path, *path_full;
|
2011-12-26 12:26:11 +00:00
|
|
|
int index = -1;
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2011-10-10 07:10:53 +00:00
|
|
|
PYRNA_STRUCT_CHECK_OBJ(self);
|
2011-03-02 04:51:43 +00:00
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "s|i:driver_add", &path, &index))
|
|
|
|
return NULL;
|
|
|
|
|
2013-01-10 15:22:19 +00:00
|
|
|
if (pyrna_struct_anim_args_parse(&self->ptr, "bpy_struct.driver_add():", path, &path_full, &index) == -1) {
|
2011-03-02 04:51:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
2011-12-26 12:26:11 +00:00
|
|
|
PyObject *ret = NULL;
|
2011-03-02 04:51:43 +00:00
|
|
|
ReportList reports;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
BKE_reports_init(&reports, RPT_STORE);
|
|
|
|
|
Tweaks to New Driver creation behaviour
* 'Show Debug' now enabled for all newly created drivers. For most users, it is
useful to be able to see this to help figure out what's going on
* Removed failed experiment of creating new drivers with Generator FModifiers. I
had hoped that this would make it easier to create drivers that doubled or
halved the input values, but that has proved to not be the case, and instead
made harder for most users to set things up (as they'd have to remove these
first).
Now, when adding drivers from the UI, these get created with two keyframes (at
(0,0) and (1,1) for a 1-1 mapping), which can be easily tweaked normally.
However, for backwards compatability of scripts (notably rigify, and perhaps
some others out there), when creating drivers from scripts, they will still get
created with Generator FModifiers for now. We can review this situation again
for 2.7, but for now it seems ok.
2013-09-03 00:28:23 +00:00
|
|
|
result = ANIM_add_driver(&reports, (ID *)self->ptr.id.data, path_full, index,
|
|
|
|
CREATEDRIVER_WITH_FMODIFIER, DRIVER_TYPE_PYTHON);
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2013-01-07 05:26:12 +00:00
|
|
|
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)
|
2011-03-02 04:51:43 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (result) {
|
2011-12-26 12:26:11 +00:00
|
|
|
ID *id = self->ptr.id.data;
|
|
|
|
AnimData *adt = BKE_animdata_from_id(id);
|
2011-03-02 04:51:43 +00:00
|
|
|
FCurve *fcu;
|
|
|
|
|
|
|
|
PointerRNA tptr;
|
|
|
|
PyObject *item;
|
|
|
|
|
2011-10-13 01:29:08 +00:00
|
|
|
if (index == -1) { /* all, use a list */
|
2011-12-26 12:26:11 +00:00
|
|
|
int i = 0;
|
|
|
|
ret = PyList_New(0);
|
|
|
|
while ((fcu = list_find_fcurve(&adt->drivers, path_full, i++))) {
|
2011-03-02 04:51:43 +00:00
|
|
|
RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr);
|
2011-12-26 12:26:11 +00:00
|
|
|
item = pyrna_struct_CreatePyObject(&tptr);
|
2011-03-02 04:51:43 +00:00
|
|
|
PyList_Append(ret, item);
|
|
|
|
Py_DECREF(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-12-26 12:26:11 +00:00
|
|
|
fcu = list_find_fcurve(&adt->drivers, path_full, index);
|
2011-03-02 04:51:43 +00:00
|
|
|
RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr);
|
2011-12-26 12:26:11 +00:00
|
|
|
ret = pyrna_struct_CreatePyObject(&tptr);
|
2011-03-02 04:51:43 +00:00
|
|
|
}
|
2011-05-08 05:41:57 +00:00
|
|
|
|
2012-03-26 20:41:54 +00:00
|
|
|
WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION | ND_FCURVES_ORDER, NULL);
|
2011-03-02 04:51:43 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* XXX, should be handled by reports, */
|
|
|
|
PyErr_SetString(PyExc_TypeError, "bpy_struct.driver_add(): failed because of an internal error");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN((void *)path_full);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char pyrna_struct_driver_remove_doc[] =
|
|
|
|
".. method:: driver_remove(path, index=-1)\n"
|
|
|
|
"\n"
|
|
|
|
" Remove driver(s) from the given property\n"
|
|
|
|
"\n"
|
|
|
|
" :arg path: path to the property to drive, analogous to the fcurve's data path.\n"
|
|
|
|
" :type path: string\n"
|
|
|
|
" :arg index: array index of the property drive. Defaults to -1 for all indices or a single channel if the property is not an array.\n"
|
|
|
|
" :type index: int\n"
|
|
|
|
" :return: Success of driver removal.\n"
|
|
|
|
" :rtype: boolean\n"
|
|
|
|
;
|
|
|
|
PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
|
|
|
|
{
|
|
|
|
const char *path, *path_full;
|
2011-12-26 12:26:11 +00:00
|
|
|
int index = -1;
|
2011-03-02 04:51:43 +00:00
|
|
|
|
2011-10-10 07:10:53 +00:00
|
|
|
PYRNA_STRUCT_CHECK_OBJ(self);
|
2011-03-02 04:51:43 +00:00
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "s|i:driver_remove", &path, &index))
|
|
|
|
return NULL;
|
|
|
|
|
2013-01-10 15:22:19 +00:00
|
|
|
if (pyrna_struct_anim_args_parse(&self->ptr, "bpy_struct.driver_remove():", path, &path_full, &index) == -1) {
|
2011-03-02 04:51:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
short result;
|
|
|
|
ReportList reports;
|
|
|
|
|
|
|
|
BKE_reports_init(&reports, RPT_STORE);
|
|
|
|
|
2011-12-26 12:26:11 +00:00
|
|
|
result = ANIM_remove_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0);
|
2011-03-02 04:51:43 +00:00
|
|
|
|
|
|
|
MEM_freeN((void *)path_full);
|
|
|
|
|
2013-01-07 05:26:12 +00:00
|
|
|
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1)
|
2011-03-02 04:51:43 +00:00
|
|
|
return NULL;
|
2011-05-08 05:41:57 +00:00
|
|
|
|
2012-03-26 20:41:54 +00:00
|
|
|
WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION | ND_FCURVES_ORDER, NULL);
|
2011-03-02 04:51:43 +00:00
|
|
|
|
|
|
|
return PyBool_FromLong(result);
|
|
|
|
}
|
|
|
|
}
|