MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / sListDocuments

Method sListDocuments

src/App/ApplicationPy.cpp:1010–1038  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1008}
1009
1010PyObject* ApplicationPy::sListDocuments(PyObject* /*self*/, PyObject* args)
1011{
1012 PyObject* sort = Py_False;
1013 if (!PyArg_ParseTuple(args, "|O!", &PyBool_Type, &sort)) {
1014 return nullptr;
1015 }
1016 PY_TRY
1017 {
1018 PyObject* pDict = PyDict_New();
1019 PyObject* pKey {};
1020 Base::PyObjectBase* pValue {};
1021
1022 std::vector<Document*> docs = GetApplication().getDocuments();
1023 ;
1024 if (Base::asBoolean(sort)) {
1025 docs = Document::getDependentDocuments(docs, true);
1026 }
1027
1028 for (auto doc : docs) {
1029 pKey = PyUnicode_FromString(doc->getName());
1030 // GetPyObject() increments
1031 pValue = static_cast<Base::PyObjectBase*>(doc->getPyObject());
1032 PyDict_SetItem(pDict, pKey, pValue);
1033 // now we can decrement again as PyDict_SetItem also has incremented
1034 pValue->DecRef();
1035 }
1036
1037 return pDict;
1038 }
1039 PY_CATCH;
1040}
1041

Callers

nothing calls this directly

Calls 4

asBooleanFunction · 0.85
getDocumentsMethod · 0.80
getNameMethod · 0.45
getPyObjectMethod · 0.45

Tested by

no test coverage detected