Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
App: add DocumentObjectPy.evalExpression()
Allow easy evlauation of expression.
  • Loading branch information
realthunder authored and wwmayer committed Oct 7, 2019
1 parent 29f5ac7 commit 533bbf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/App/DocumentObjectPy.xml
Expand Up @@ -55,6 +55,11 @@
<UserDocu>Register an expression for a property</UserDocu>
</Documentation>
</Methode>
<Methode Name="evalExpression">
<Documentation>
<UserDocu>Evaluate an expression</UserDocu>
</Documentation>
</Methode>
<Methode Name="recompute">
<Documentation>
<UserDocu>recompute(recursive=False): Recomputes this object</UserDocu>
Expand Down
14 changes: 14 additions & 0 deletions src/App/DocumentObjectPyImp.cpp
Expand Up @@ -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<Expression> 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;
Expand Down

0 comments on commit 533bbf8

Please sign in to comment.