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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user