diff options
author | Joshua Leung <aligorith@gmail.com> | 2011-04-26 17:49:40 +0400 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2011-04-26 17:49:40 +0400 |
commit | 64a37fadf09e32772520272a831034a9fe790fc8 (patch) | |
tree | 6cadbf712bc9186b731cfeeda256d2228820da5f /source/blender/makesrna/intern/rna_animation.c | |
parent | 481aed1d0e7f943b9b7caa12a890c0cc4286ac00 (diff) |
Adding support for adding copies of existing drivers to other animdata
blocks via PyAPI/RNA
For example:
ob = bpy.context.active_object # assumes default cube has some drivers
added already before running script
dst = bpy.data.objects["Camera"]
adt = dst.animation_data_create()
for driver in ob.animation_data.drivers:
new_driver = adt.drivers.from_existing(driver)
Diffstat (limited to 'source/blender/makesrna/intern/rna_animation.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_animation.c | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c index 8e210a7a4cb..fb23e5ac63d 100644 --- a/source/blender/makesrna/intern/rna_animation.c +++ b/source/blender/makesrna/intern/rna_animation.c @@ -55,6 +55,7 @@ EnumPropertyItem keyingset_path_grouping_items[] = { #ifdef RNA_RUNTIME #include "BKE_animsys.h" +#include "BKE_fcurve.h" #include "BKE_nla.h" #include "WM_api.h" @@ -457,6 +458,24 @@ static void rna_NlaTrack_active_set(PointerRNA *ptr, PointerRNA value) BKE_nlatrack_set_active(&adt->nla_tracks, track); } + +static FCurve *rna_Driver_from_existing(AnimData *adt, bContext *C, FCurve *src_driver) +{ + /* verify that we've got a driver to duplicate */ + if (ELEM(NULL, src_driver, src_driver->driver)) { + BKE_reportf(CTX_wm_reports(C), RPT_ERROR, "No valid driver data to create copy of"); + return NULL; + } + else { + /* just make a copy of the existing one and add to self */ + FCurve *new_fcu = copy_fcurve(src_driver); + + // XXX: if we impose any ordering on these someday, this will be problematic + BLI_addtail(&adt->drivers, new_fcu); + return new_fcu; + } +} + #else /* helper function for Keying Set -> keying settings */ @@ -724,7 +743,7 @@ static void rna_api_animdata_nla_tracks(BlenderRNA *brna, PropertyRNA *cprop) func = RNA_def_function(srna, "new", "rna_NlaTrack_new"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); - RNA_def_function_ui_description(func, "Add a new NLA Tracks"); + RNA_def_function_ui_description(func, "Add a new NLA Track"); RNA_def_pointer(func, "prev", "NlaTrack", "", "NLA Track to add the new one after."); /* return type */ parm = RNA_def_pointer(func, "track", "NlaTrack", "", "New NLA Track."); @@ -745,6 +764,28 @@ static void rna_api_animdata_nla_tracks(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_property_update(prop, NC_ANIMATION|ND_NLA|NA_SELECTED, NULL); } +static void rna_api_animdata_drivers(BlenderRNA *brna, PropertyRNA *cprop) +{ + StructRNA *srna; + PropertyRNA *parm; + FunctionRNA *func; + + PropertyRNA *prop; + + RNA_def_property_srna(cprop, "AnimDataDrivers"); + srna= RNA_def_struct(brna, "AnimDataDrivers", NULL); + RNA_def_struct_sdna(srna, "AnimData"); + RNA_def_struct_ui_text(srna, "Drivers", "Collection of Driver F-Curves"); + + func = RNA_def_function(srna, "from_existing", "rna_Driver_from_existing"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a new driver given an existing one"); + RNA_def_pointer(func, "src_driver", "FCurve", "", "Existing Driver F-Curve to use as template for a new one"); + /* return type */ + parm = RNA_def_pointer(func, "driver", "FCurve", "", "New Driver F-Curve."); + RNA_def_function_return(func, parm); +} + void rna_def_animdata_common(StructRNA *srna) { PropertyRNA *prop; @@ -774,7 +815,7 @@ void rna_def_animdata(BlenderRNA *brna) /* Active Action */ prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE); RNA_def_property_flag(prop, PROP_EDITABLE); /* this flag as well as the dynamic test must be defined for this to be editable... */ - RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Action_id_poll"); + RNA_def_property_pointer_funcs(prop, NULL, "rna_AnimData_action_set", NULL, "rna_Action_id_poll"); RNA_def_property_editable_func(prop, "rna_AnimData_action_editable"); RNA_def_property_ui_text(prop, "Action", "Active Action for this datablock"); RNA_def_property_update(prop, NC_ANIMATION, NULL); /* this will do? */ @@ -805,6 +846,8 @@ void rna_def_animdata(BlenderRNA *brna) RNA_def_property_struct_type(prop, "FCurve"); RNA_def_property_ui_text(prop, "Drivers", "The Drivers/Expressions for this datablock"); + rna_api_animdata_drivers(brna, prop); + /* General Settings */ prop= RNA_def_property(srna, "use_nla", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ADT_NLA_EVAL_OFF); |