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

Method removeObject

src/App/DocumentPyImp.cpp:421–457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419}
420
421PyObject* DocumentPy::removeObject(PyObject* args)
422{
423 char* sName {};
424 if (PyArg_ParseTuple(args, "s", &sName)) {
425 DocumentObject* object = getDocumentPtr()->getObject(sName);
426 if (object) {
427 getDocumentPtr()->removeObject(sName);
428 Py_Return;
429 }
430
431 std::stringstream str;
432 str << "No document object found with name '" << sName << "'" << std::ends;
433 throw Py::ValueError(str.str());
434 }
435
436 PyErr_Clear();
437 PyObject* objpy {};
438 if (PyArg_ParseTuple(args, "O!", &App::DocumentObjectPy::Type, &objpy)) {
439 DocumentObject* object = static_cast<App::DocumentObjectPy*>(objpy)->getDocumentObjectPtr();
440 if (!object) {
441 PyErr_Format(PyExc_RuntimeError, "Invalid document object");
442 return nullptr;
443 }
444
445 if (object->getDocument() == getDocumentPtr()) {
446 getDocumentPtr()->removeObject(object);
447 Py_Return;
448 }
449
450 std::stringstream str;
451 str << "Document object is not part of this document";
452 throw Py::ValueError(str.str());
453 }
454
455 PyErr_SetString(PyExc_TypeError, "Expect str or DocumentObject");
456 return nullptr;
457}
458
459PyObject* DocumentPy::copyObject(PyObject* args, PyObject* kwd)
460{

Callers

nothing calls this directly

Calls 3

getObjectMethod · 0.45
strMethod · 0.45
getDocumentMethod · 0.45

Tested by

no test coverage detected