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:
@@ -232,6 +232,13 @@ Return tuple(obj,newElementName,oldElementName)
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Methode Name="isAttachedToDocument" Const="true">
|
||||
<Documentation>
|
||||
<UserDocu>
|
||||
isAttachedToDocument(): return true if the object is part of a document, false otherwise
|
||||
</UserDocu>
|
||||
</Documentation>
|
||||
</Methode>
|
||||
<Attribute Name="OutList" ReadOnly="true">
|
||||
<Documentation>
|
||||
<UserDocu>A list of all objects this object links to.</UserDocu>
|
||||
@@ -266,7 +273,7 @@ Return tuple(obj,newElementName,oldElementName)
|
||||
<Documentation>
|
||||
<UserDocu>Return the internal name of this object</UserDocu>
|
||||
</Documentation>
|
||||
<Parameter Name="Name" Type="String"/>
|
||||
<Parameter Name="Name" Type="Object"/>
|
||||
</Attribute>
|
||||
<Attribute Name="Document" ReadOnly="true">
|
||||
<Documentation>
|
||||
|
||||
@@ -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