diff --git a/src/App/DocumentObjectPy.xml b/src/App/DocumentObjectPy.xml index 7424fc9a58..463c013edf 100644 --- a/src/App/DocumentObjectPy.xml +++ b/src/App/DocumentObjectPy.xml @@ -232,6 +232,13 @@ Return tuple(obj,newElementName,oldElementName) + + + + isAttachedToDocument(): return true if the object is part of a document, false otherwise + + + A list of all objects this object links to. @@ -266,7 +273,7 @@ Return tuple(obj,newElementName,oldElementName) Return the internal name of this object - + diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index 36e863c8f2..af09d7d998 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -49,14 +49,14 @@ std::string DocumentObjectPy::representation() const return str.str(); } -Py::String DocumentObjectPy::getName() const +Py::Object DocumentObjectPy::getName() const { DocumentObject* object = this->getDocumentObjectPtr(); const char* internal = object->getNameInDocument(); if (!internal) { - throw Py::RuntimeError(std::string("This object is currently not part of a document")); + return Py::None(); } - return {std::string(internal)}; + return Py::String(internal); } Py::String DocumentObjectPy::getFullName() const @@ -76,6 +76,17 @@ Py::Object DocumentObjectPy::getDocument() const } } +PyObject* DocumentObjectPy::isAttachedToDocument(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) { + return nullptr; + } + + DocumentObject* object = this->getDocumentObjectPtr(); + bool ok = object->isAttachedToDocument(); + return Py::new_reference_to(Py::Boolean(ok)); +} + PyObject* DocumentObjectPy::addProperty(PyObject *args, PyObject *kwd) { char *sType,*sName=nullptr,*sGroup=nullptr,*sDoc=nullptr;