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

Method sLoadFile

src/Gui/ApplicationPy.cpp:2025–2056  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2023}
2024
2025PyObject* ApplicationPy::sLoadFile(PyObject* /*self*/, PyObject* args)
2026{
2027 const char* path = "";
2028 const char* mod = "";
2029 if (!PyArg_ParseTuple(args, "s|s", &path, &mod)) {
2030 return nullptr;
2031 }
2032
2033 PY_TRY
2034 {
2035 Base::FileInfo fi(path);
2036 if (!fi.isFile() || !fi.exists()) {
2037 PyErr_Format(PyExc_IOError, "File %s doesn't exist.", path);
2038 return nullptr;
2039 }
2040
2041 std::string module = mod;
2042 if (module.empty()) {
2043 std::string ext = fi.extension();
2044 std::vector<std::string> modules = App::GetApplication().getImportModules(ext.c_str());
2045 if (modules.empty()) {
2046 PyErr_Format(PyExc_IOError, "Filetype %s is not supported.", ext.c_str());
2047 return nullptr;
2048 }
2049
2050 module = modules.front();
2051 }
2052
2053 Application::Instance->open(path, module.c_str());
2054
2055 Py_Return;
2056 }
2057 PY_CATCH
2058}
2059

Callers

nothing calls this directly

Calls 8

isFileMethod · 0.80
getImportModulesMethod · 0.80
existsMethod · 0.45
emptyMethod · 0.45
extensionMethod · 0.45
c_strMethod · 0.45
frontMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected