Skip to content

Commit 8536c1c

Browse files
committed
[SofaPython3] Add type coercion from numpy array to sofa parsable string (in object creation)
So we can write: ```python def createScene(root): root.addObject("MechanicalObject", name="loader", filename="mesh/cube.obj") root.addObject("MechanicalObject", name="dofs", position=root.loader.position) # to make a link root.addObject("MechanicalObject", name="dofs", position=root.loader.position.value) # to make a copy by value ```
1 parent 5001e63 commit 8536c1c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

Plugin/src/SofaPython3/DataHelper.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@ std::string toSofaParsableString(const py::handle& p)
5252
if(py::isinstance<sofa::core::objectmodel::BaseData>(p))
5353
{
5454
sofa::core::objectmodel::BaseData* data = py::cast<sofa::core::objectmodel::BaseData*>(p);
55-
return data->getValueString();
55+
return data->getLinkPath();
5656
}
57+
58+
// If the object is a numpy array we convert it to a list then to a sofa string
59+
if(py::isinstance<py::array>(p))
60+
{
61+
py::object o = p.attr("tolist")();
62+
return toSofaParsableString(o);
63+
}
64+
5765
return py::repr(p);
5866
}
5967

0 commit comments

Comments
 (0)