- //Add a new result object
- Handle(GEOM_Object) result = GetEngine()->AddObject(GetDocID(), GEOM_IMPORT);
-
- //Add an Import function
- Handle(GEOM_Function) aFunction = result->AddFunction(GEOMImpl_ImportDriver::GetID(), IMPORT_SHAPE);
- if (aFunction.IsNull()) return result;
-
- //Check if the function is set correctly
- if (aFunction->GetDriverGUID() != GEOMImpl_ImportDriver::GetID()) return result;
-
- Handle(TCollection_HAsciiString) aHLibName;
- if (!IsSupported(Standard_True, theFormatName, aHLibName)) {
- return result;
- }
- TCollection_AsciiString aLibName = aHLibName->String();
-
- //Set parameters
- GEOMImpl_IImportExport aCI (aFunction);
- aCI.SetFileName(theFileName);
- aCI.SetFormatName(theFormatName);
- aCI.SetPluginName(aLibName);
-
- //Perform the Import
- try {
-#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
- OCC_CATCH_SIGNALS;
-#endif
- if (!GetSolver()->ComputeFunction(aFunction)) {
- SetErrorCode("Import driver failed");
- return NULL;
- }
- }
- catch (Standard_Failure) {
- Handle(Standard_Failure) aFail = Standard_Failure::Caught();
- SetErrorCode(aFail->GetMessageString());
- return NULL;
- }
-
- //Make a Python command
- GEOM::TPythonDump(aFunction) << result << " = geompy.Import(\""
- << theFileName.ToCString() << "\", \"" << theFormatName.ToCString() << "\")";
-