From 1ade42e634a3213b0a22bf35dd13b3a61e8314ff Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 15 May 2023 23:40:25 +0200 Subject: [PATCH] App: expose function getParent() to Python --- src/App/DocumentObjectPy.xml | 9 +++++++++ src/App/DocumentObjectPyImp.cpp | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/App/DocumentObjectPy.xml b/src/App/DocumentObjectPy.xml index ac0f7cea1e..ead1d5573c 100644 --- a/src/App/DocumentObjectPy.xml +++ b/src/App/DocumentObjectPy.xml @@ -182,6 +182,15 @@ Return -1 if element visibility is not supported or element not found, 0 if invi in a single group, hence only a single return value. + + + Returns the group the object is in or None if it is not part of a group. + Note that an object can only be in a single group, hence only a single return + value. + The parent can be a simple group as with getParentGroup() or a + GeoFeature group as with getParentGeoFeatureGroup(). + + Get all paths from this object to another object following the OutList. diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index 810c0f33e0..b561983bfe 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -673,6 +673,24 @@ PyObject* DocumentObjectPy::getParentGeoFeatureGroup(PyObject *args) } } +PyObject* DocumentObjectPy::getParent(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + try { + auto grp = getDocumentObjectPtr()->getFirstParent(); + if(!grp) { + Py_INCREF(Py_None); + return Py_None; + } + return grp->getPyObject(); + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } +} + Py::Boolean DocumentObjectPy::getMustExecute() const { try {