From cd577f02b95ebad9948b448f7fcb370244223698 Mon Sep 17 00:00:00 2001 From: Falk David Date: Mon, 29 Jul 2024 11:14:20 +0200 Subject: [PATCH] Python: Trigger property update in `foreach_get/set` Calling `foreach_get/set` on a collection property did not trigger a property update. In the attribute API, this lead to missing updates after e.g. setting the values of an attribute. This adds a call to `RNA_property_update` for the getter/setter bpy rna function and adds a property update callback to all the different attribute collection properties. Pull Request: https://projects.blender.org/blender/blender/pulls/125518 --- source/blender/makesrna/intern/rna_attribute.cc | 12 ++++++++++++ source/blender/python/intern/bpy_rna.cc | 3 +++ 2 files changed, 15 insertions(+) diff --git a/source/blender/makesrna/intern/rna_attribute.cc b/source/blender/makesrna/intern/rna_attribute.cc index ead9b58cb63..a26a8b192ce 100644 --- a/source/blender/makesrna/intern/rna_attribute.cc +++ b/source/blender/makesrna/intern/rna_attribute.cc @@ -962,6 +962,7 @@ static void rna_def_attribute_float(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); srna = RNA_def_struct(brna, "FloatAttributeValue", nullptr); RNA_def_struct_sdna(srna, "MFloatProperty"); @@ -995,6 +996,7 @@ static void rna_def_attribute_float_vector(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); /* Float Vector Attribute Value */ srna = RNA_def_struct(brna, "FloatVectorAttributeValue", nullptr); @@ -1034,6 +1036,7 @@ static void rna_def_attribute_float_color(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); /* Float Color Attribute Value */ srna = RNA_def_struct(brna, "FloatColorAttributeValue", nullptr); @@ -1082,6 +1085,7 @@ static void rna_def_attribute_byte_color(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); /* Byte Color Attribute Value */ srna = RNA_def_struct(brna, "ByteColorAttributeValue", nullptr); @@ -1131,6 +1135,7 @@ static void rna_def_attribute_int(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); srna = RNA_def_struct(brna, "IntAttributeValue", nullptr); RNA_def_struct_sdna(srna, "MIntProperty"); @@ -1161,6 +1166,7 @@ static void rna_def_attribute_string(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); srna = RNA_def_struct(brna, "StringAttributeValue", nullptr); RNA_def_struct_sdna(srna, "MStringProperty"); @@ -1195,6 +1201,7 @@ static void rna_def_attribute_bool(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); srna = RNA_def_struct(brna, "BoolAttributeValue", nullptr); RNA_def_struct_sdna(srna, "MBoolProperty"); @@ -1225,6 +1232,7 @@ static void rna_def_attribute_int8(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); srna = RNA_def_struct(brna, "ByteIntAttributeValue", nullptr); RNA_def_struct_sdna(srna, "MInt8Property"); @@ -1256,6 +1264,7 @@ static void rna_def_attribute_int2(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); srna = RNA_def_struct(brna, "Int2AttributeValue", nullptr); RNA_def_struct_sdna(srna, "vec2i"); @@ -1290,6 +1299,7 @@ static void rna_def_attribute_quaternion(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); srna = RNA_def_struct(brna, "QuaternionAttributeValue", nullptr); RNA_def_struct_sdna(srna, "vec4f"); @@ -1325,6 +1335,7 @@ static void rna_def_attribute_float4x4(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); srna = RNA_def_struct(brna, "Float4x4AttributeValue", nullptr); RNA_def_struct_sdna(srna, "mat4x4f"); @@ -1360,6 +1371,7 @@ static void rna_def_attribute_float2(BlenderRNA *brna) nullptr, nullptr, nullptr); + RNA_def_property_update(prop, 0, "rna_Attribute_update_data"); /* Float2 Attribute Value */ srna = RNA_def_struct(brna, "Float2AttributeValue", nullptr); diff --git a/source/blender/python/intern/bpy_rna.cc b/source/blender/python/intern/bpy_rna.cc index c06789f7ed7..68697d55623 100644 --- a/source/blender/python/intern/bpy_rna.cc +++ b/source/blender/python/intern/bpy_rna.cc @@ -5742,6 +5742,9 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) return nullptr; } + if (set) { + RNA_property_update(BPY_context_get(), &self->ptr, self->prop); + } Py_RETURN_NONE; }