From 4bf4444d817722408d322c969c27a9a7c6ea8bde Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Mon, 30 Sep 2019 13:41:01 +0800 Subject: [PATCH] App: add DocumentObjectPy.evalExpression() Allow easy evlauation of expression. --- src/App/DocumentObjectPy.xml | 5 +++++ src/App/DocumentObjectPyImp.cpp | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/App/DocumentObjectPy.xml b/src/App/DocumentObjectPy.xml index 50633d38bb..288f351214 100644 --- a/src/App/DocumentObjectPy.xml +++ b/src/App/DocumentObjectPy.xml @@ -55,6 +55,11 @@ Register an expression for a property + + + Evaluate an expression + + recompute(recursive=False): Recomputes this object diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index 182d6bc520..5da0b636d7 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -368,6 +368,20 @@ PyObject* DocumentObjectPy::setExpression(PyObject * args) Py_Return; } +PyObject* DocumentObjectPy::evalExpression(PyObject * args) +{ + const char *expr; + if (!PyArg_ParseTuple(args, "s", &expr)) // convert args: Python->C + return NULL; // NULL triggers exception + + PY_TRY { + boost::shared_ptr shared_expr(Expression::parse(getDocumentObjectPtr(), expr)); + if(shared_expr) + return Py::new_reference_to(shared_expr->getPyValue()); + Py_Return; + } PY_CATCH +} + PyObject* DocumentObjectPy::recompute(PyObject *args) { PyObject *recursive=Py_False;