Core: Fix macro recording when using module_io
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
from FreeCAD import Base
|
||||
import importlib
|
||||
|
||||
|
||||
def OpenInsertObject(importerModule, objectPath, importMethod, docName = ""):
|
||||
def OpenInsertObject(importerName, objectPath, importMethod, docName = ""):
|
||||
try:
|
||||
importArgs = []
|
||||
importKwargs = {}
|
||||
|
||||
importerModule = importlib.import_module(importerName)
|
||||
|
||||
if docName:
|
||||
importArgs.append(docName)
|
||||
if hasattr(importerModule, "importOptions"):
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#endif
|
||||
|
||||
#include <QLoggingCategory>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObjectPy.h>
|
||||
@@ -637,21 +638,10 @@ void Application::open(const char* FileName, const char* Module)
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Load using provided python module
|
||||
{
|
||||
Base::PyGILStateLocker locker;
|
||||
Py::Module moduleIo(PyImport_ImportModule("freecad.module_io"));
|
||||
const auto dictS = moduleIo.getDict().keys().as_string();
|
||||
if (!moduleIo.isNull() && moduleIo.hasAttr("OpenInsertObject"))
|
||||
{
|
||||
const Py::TupleN args(
|
||||
Py::Module(PyImport_ImportModule(Module)),
|
||||
Py::String(unicodepath),
|
||||
Py::String("open")
|
||||
);
|
||||
moduleIo.callMemberFunction("OpenInsertObject", args);
|
||||
}
|
||||
}
|
||||
std::string code = fmt::format("from freecad import module_io\n"
|
||||
"module_io.OpenInsertObject(\"{}\", \"{}\", \"{}\")\n",
|
||||
Module, unicodepath, "open");
|
||||
Gui::Command::runCommand(Gui::Command::App, code.c_str());
|
||||
|
||||
// ViewFit
|
||||
if (sendHasMsgToActiveView("ViewFit")) {
|
||||
@@ -716,22 +706,10 @@ void Application::importFrom(const char* FileName, const char* DocName, const ch
|
||||
}
|
||||
}
|
||||
|
||||
// Load using provided python module
|
||||
{
|
||||
Base::PyGILStateLocker locker;
|
||||
Py::Module moduleIo(PyImport_ImportModule("freecad.module_io"));
|
||||
const auto dictS = moduleIo.getDict().keys().as_string();
|
||||
if (!moduleIo.isNull() && moduleIo.hasAttr("OpenInsertObject"))
|
||||
{
|
||||
const Py::TupleN args(
|
||||
Py::Module(PyImport_ImportModule(Module)),
|
||||
Py::String(unicodepath),
|
||||
Py::String("insert"),
|
||||
Py::String(DocName)
|
||||
);
|
||||
moduleIo.callMemberFunction("OpenInsertObject", args);
|
||||
}
|
||||
}
|
||||
std::string code = fmt::format("from freecad import module_io\n"
|
||||
"module_io.OpenInsertObject(\"{}\", \"{}\", \"{}\", \"{}\")\n",
|
||||
Module, unicodepath, "insert", DocName);
|
||||
Gui::Command::runCommand(Gui::Command::App, code.c_str());
|
||||
|
||||
// Commit the transaction
|
||||
if (doc && !pendingCommand) {
|
||||
|
||||
Reference in New Issue
Block a user