diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2020-06-24 22:10:43 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2020-06-25 12:10:18 +0300 |
commit | 64a584b38a73d4745e02620051592c5b05439647 (patch) | |
tree | 9d60be41bd088dc9ec9313305722bee184cdb9b4 /source/blender/makesrna/intern/rna_object.c | |
parent | 6b53e0adbc5fee508da580bdb8feb596e36751bc (diff) |
Python API: add methods to allow copying of constraints.
Blender has an operator to do Copy & Paste of constraints between
objects and bones, but no simple method to do that directly via
the Python API is provided. This adds a copy() method to object
and pose bone constraint collections.
Differential Revision: https://developer.blender.org/D8112
Diffstat (limited to 'source/blender/makesrna/intern/rna_object.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 1f111474aa3..baa5b50104b 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1497,6 +1497,17 @@ static void rna_Object_constraints_move( WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT, object); } +static bConstraint *rna_Object_constraints_copy(Object *object, Main *bmain, PointerRNA *con_ptr) +{ + bConstraint *con = con_ptr->data; + bConstraint *new_con = BKE_constraint_copy_for_object(object, con); + + ED_object_constraint_tag_update(bmain, object, new_con); + WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_ADDED, object); + + return new_con; +} + bool rna_Object_constraints_override_apply(Main *UNUSED(bmain), PointerRNA *ptr_dst, PointerRNA *ptr_src, @@ -2217,6 +2228,21 @@ static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); parm = RNA_def_int(func, "to_index", -1, INT_MIN, INT_MAX, "To Index", "Target index", 0, 10000); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); + + func = RNA_def_function(srna, "copy", "rna_Object_constraints_copy"); + RNA_def_function_ui_description(func, "Add a new constraint that is a copy of the given one"); + RNA_def_function_flag(func, FUNC_USE_MAIN); + /* constraint to copy */ + parm = RNA_def_pointer(func, + "constraint", + "Constraint", + "", + "Constraint to copy - may belong to a different object"); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR); + RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0); + /* return type */ + parm = RNA_def_pointer(func, "new_constraint", "Constraint", "", "New constraint"); + RNA_def_function_return(func, parm); } /* object.modifiers */ |