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.
This commit is contained in:
parent
96f762500e
commit
abe32d2a35
Notes:
blender-bot
2023-02-14 04:38:05 +01:00
Referenced by issue #58964, Python: "drivers_remove" not working and crashing with invalid drivers
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue