diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.cpp b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.cpp
index cc51a990..02bc214a 100644
--- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.cpp
+++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.cpp
@@ -25,7 +25,6 @@ along with sofaqtquick. If not, see .
- thierry.gaugry@inria.fr
********************************************************************/
-
#include
#include
@@ -395,6 +394,19 @@ py::object BindingBase::getData(Base& self, const std::string& s)
return py::none();
}
+py::object BindingBase::setDataValues(Base& self, py::kwargs kwargs)
+{
+ for(auto key : kwargs)
+ {
+ BaseData* d = self.findData(py::cast(key.first));
+ if(d!=nullptr)
+ PythonFactory::fromPython(d, py::cast(key.second));
+ else
+ throw py::attribute_error("There is no data field named: "+py::cast(key.first));
+ }
+ return py::none();
+}
+
void moduleAddBase(py::module &m)
{
py::class_ base(m, "Base", py::dynamic_attr(), doc::base::BaseClass);
@@ -428,6 +440,7 @@ void moduleAddBase(py::module &m)
base.def("getLoggedMessagesAsString", &BindingBase::getLoggedMessagesAsString, sofapython3::doc::base::getLoggedMessagesAsString);
base.def("countLoggedMessages", &BindingBase::countLoggedMessages, sofapython3::doc::base::countLoggedMessages);
base.def("clearLoggedMessages", &BindingBase::clearLoggedMessages, sofapython3::doc::base::clearLoggedMessages);
+ base.def("setDataValues", &BindingBase::setDataValues, sofapython3::doc::base::setDataValues);
}
} /// namespace sofapython3
diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.h b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.h
index f5c9616c..884107db 100644
--- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.h
+++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base.h
@@ -65,6 +65,7 @@ class BindingBase
/// Set the data field value from the array.
static void SetDataFromArray(BaseData* data, const py::array& value);
static bool SetData(BaseData* data, pybind11::object value);
+ static py::object setDataValues(Base& self, py::kwargs kwargs);
static py::list getDataFields(Base& self);
static py::list getLinks(Base& self);
diff --git a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base_doc.h b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base_doc.h
index 428a0089..870bc498 100644
--- a/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base_doc.h
+++ b/bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Base_doc.h
@@ -70,6 +70,10 @@ static auto findData =
:type name: string
:return: the data field
)";
+static auto setDataValues =
+ R"(
+ Set values for a the given data field, multiple pairs of args are allowed.
+ )";
static auto getDataFields =
R"(
Accessor to the vector containing all the fields of this object