@@ -167,14 +167,28 @@ py::object hasObject(Node &n, const std::string &name)
167167 return py::cast (false );
168168}
169169
170+ py::object getObject (Node &n, const std::string &name, const py::kwargs& kwargs)
171+ {
172+ if (kwargs.size ()!=0 )
173+ {
174+ msg_deprecated (&n) << " Calling the method getObject() with extra arguments is not supported anymore."
175+ << " To remove this message please refer to the documentation of the getObject method" ;
176+ }
177+
178+ BaseObject *object = n.getObject (name);
179+ if (object)
180+ return PythonFactory::toPython (object);
181+ return py::none ();
182+ }
183+
170184// / Implement the addObject function.
171185py::object addObjectKwargs (Node* self, const std::string& type, const py::kwargs& kwargs)
172186{
173187 if (kwargs.contains (" name" ))
174188 {
175189 std::string name = py::str (kwargs[" name" ]);
176190 if (sofapython3::isProtectedKeyword (name))
177- throw py::value_error (" addObject: Cannot call addObject with name " + name + " : Protected keyword" );
191+ throw py::value_error (" Cannot call addObject with name " + name + " : Protected keyword" );
178192 }
179193 // / Prepare the description to hold the different python attributes as data field's
180194 // / arguments then create the object.
@@ -230,7 +244,6 @@ py::object addKwargs(Node* self, const py::object& callable, const py::kwargs& k
230244 self->addChild (node);
231245 return py::cast (node);
232246 }
233-
234247 if (py::isinstance<py::str>(callable))
235248 {
236249 py::str type = callable;
@@ -507,6 +520,7 @@ void moduleAddNode(py::module &m) {
507520 p.def (" addObject" , &addObject, sofapython3::doc::sofa::core::Node::addObject, py::keep_alive<0 , 2 >());
508521 p.def (" createObject" , &createObject, sofapython3::doc::sofa::core::Node::createObject);
509522 p.def (" hasObject" , &hasObject, sofapython3::doc::sofa::core::Node::hasObject);
523+ p.def (" getObject" , &getObject, sofapython3::doc::sofa::core::Node::getObject);
510524 p.def (" addChild" , &addChildKwargs, sofapython3::doc::sofa::core::Node::addChildKwargs);
511525 p.def (" addChild" , &addChild, sofapython3::doc::sofa::core::Node::addChild);
512526 p.def (" createChild" , &createChild, sofapython3::doc::sofa::core::Node::createChild);
0 commit comments