Core: Extend DocumentObjectPy

* expose isAttachedToDocument to Python
* change DocumentObjectPy::getName() to return None instead of throwing an exception if object is not part of a document
This commit is contained in:
wmayer
2024-10-28 14:06:51 +01:00
parent c5c64a9c70
commit 974919dc7c
2 changed files with 22 additions and 4 deletions

View File

@@ -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;