diff --git a/src/App/DocumentObjectPy.xml b/src/App/DocumentObjectPy.xml
index bc1493fc6c93..f15f59399ac0 100644
--- a/src/App/DocumentObjectPy.xml
+++ b/src/App/DocumentObjectPy.xml
@@ -55,7 +55,7 @@
Register an expression for a property
-
+
Evaluate an expression
diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp
index 450ef7e69a02..88bfd1ca92c4 100644
--- a/src/App/DocumentObjectPyImp.cpp
+++ b/src/App/DocumentObjectPyImp.cpp
@@ -346,15 +346,22 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args)
Py_Return;
}
-PyObject* DocumentObjectPy::evalExpression(PyObject * args)
+PyObject* DocumentObjectPy::evalExpression(PyObject *self, PyObject * args)
{
const char *expr;
- if (!PyArg_ParseTuple(args, "s", &expr)) // convert args: Python->C
- return NULL; // NULL triggers exception
+ if (!PyArg_ParseTuple(args, "s", &expr))
+ return nullptr;
+
+ // evalExpression() is a class method and thus 'self' can either be an instance of
+ // DocumentObjectPy or a type object.
+ App::DocumentObject* obj = nullptr;
+ if (self && PyObject_TypeCheck(self, &DocumentObjectPy::Type)) {
+ obj = static_cast(self)->getDocumentObjectPtr();
+ }
PY_TRY {
- std::shared_ptr shared_expr(Expression::parse(getDocumentObjectPtr(), expr));
- if(shared_expr)
+ std::shared_ptr shared_expr(Expression::parse(obj, expr));
+ if (shared_expr)
return Py::new_reference_to(shared_expr->getPyValue());
Py_Return;
} PY_CATCH