[Bf-blender-cvs] [abe32d2a35e] master: PyAPI: Add AnimationData.drivers.new/remove methods

Campbell Barton noreply at git.blender.org
Mon Jan 7 04:07:04 CET 2019


Commit: abe32d2a35e4d3ca86caca7e5f7d212d8802107f
Author: Campbell Barton
Date:   Mon Jan 7 14:03:34 2019 +1100
Branches: master
https://developer.blender.org/rBabe32d2a35e4d3ca86caca7e5f7d212d8802107f

PyAPI: Add AnimationData.drivers.new/remove methods

Low level functions to directly create and remove drivers,
use when high level functions aren't flexible enough, see: T58964.

===================================================================

M	source/blender/makesrna/intern/rna_animation.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c
index e43b62e8a75..d97fdd111b6 100644
--- a/source/blender/makesrna/intern/rna_animation.c
+++ b/source/blender/makesrna/intern/rna_animation.c
@@ -579,6 +579,33 @@ static FCurve *rna_Driver_from_existing(AnimData *adt, bContext *C, FCurve *src_
 	}
 }
 
+static FCurve *rna_Driver_new(ID *id, AnimData *adt, ReportList *reports, const char *rna_path, int array_index)
+{
+	if (rna_path[0] == '\0') {
+		BKE_report(reports, RPT_ERROR, "F-Curve data path empty, invalid argument");
+		return NULL;
+	}
+
+	if (list_find_fcurve(&adt->drivers, rna_path, array_index)) {
+		BKE_reportf(reports, RPT_ERROR, "Driver '%s[%d]' already exists", rna_path, array_index);
+		return NULL;
+	}
+
+	short add_mode = 1;
+	FCurve *fcu = verify_driver_fcurve(id, rna_path, array_index, add_mode);
+	BLI_assert(fcu != NULL);
+	return fcu;
+}
+
+static void rna_Driver_remove(AnimData *adt, ReportList *reports, FCurve *fcu)
+{
+	if (!BLI_remlink_safe(&adt->drivers, fcu)) {
+		BKE_report(reports, RPT_ERROR, "Driver not found in this animation data");
+		return;
+	}
+	free_fcurve(fcu);
+}
+
 static FCurve *rna_Driver_find(AnimData *adt, ReportList *reports, const char *data_path, int index)
 {
 	if (data_path[0] == '\0') {
@@ -1005,6 +1032,24 @@ static void rna_api_animdata_drivers(BlenderRNA *brna, PropertyRNA *cprop)
 	RNA_def_struct_sdna(srna, "AnimData");
 	RNA_def_struct_ui_text(srna, "Drivers", "Collection of Driver F-Curves");
 
+	/* Match: ActionFCurves.new/remove */
+
+	/* AnimData.drivers.new(...) */
+	func = RNA_def_function(srna, "new", "rna_Driver_new");
+	RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS);
+	parm = RNA_def_string(func, "data_path", NULL, 0, "Data Path", "F-Curve data path to use");
+	RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+	RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX);
+	/* return type */
+	parm = RNA_def_pointer(func, "driver", "FCurve", "", "Newly Driver F-Curve");
+	RNA_def_function_return(func, parm);
+
+	/* AnimData.drivers.remove(...) */
+	func = RNA_def_function(srna, "remove", "rna_Driver_remove");
+	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	parm = RNA_def_pointer(func, "driver", "FCurve", "", "");
+	RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+
 	/* AnimData.drivers.from_existing(...) */
 	func = RNA_def_function(srna, "from_existing", "rna_Driver_from_existing");
 	RNA_def_function_flag(func, FUNC_USE_CONTEXT);



More information about the Bf-blender-cvs mailing list