/// <summary> /// Read in the IFC file specified by ifcFilePath, and report any errors. /// </summary> /// <param name="ifcFilePath">The IFC file name.</param> /// <returns>True if the file read was successful, false otherwise.</returns> private bool ProcessFile(string ifcFilePath) { IFCFileReadOptions readOptions = new IFCFileReadOptions(); readOptions.FileName = ifcFilePath; readOptions.XMLConfigFileName = Path.Combine(RevitProgramPath, "EDM\\ifcXMLconfiguration.xml"); int numErrors = 0; int numWarnings = 0; try { Importer.TheCache.StatusBar.Set(String.Format(Resources.IFCReadingFile, TheFileName)); m_IfcFile.Read(readOptions, out numErrors, out numWarnings); } catch (Exception ex) { Importer.TheLog.LogError(-1, "There was an error reading the IFC file: " + ex.Message + ". Aborting import.", false); return(false); } if (numErrors > 0 || numWarnings > 0) { if (numErrors > 0) { if (numWarnings > 0) { Importer.TheLog.LogError(-1, "There were " + numErrors + " errors and " + numWarnings + " reading the IFC file. Please look at the log information at the end of this report for more information.", false); } else { Importer.TheLog.LogError(-1, "There were " + numErrors + " errors reading the IFC file. Please look at the log information at the end of this report for more information.", false); } } else { Importer.TheLog.LogWarning(-1, "There were " + numWarnings + " warnings reading the IFC file. Please look at the log information at the end of this report for more information.", false); } } return(true); }
/// <summary> /// Do a Parametric import operation. /// </summary> /// <param name="importer">The internal ImporterIFC class that contains necessary information for the import.</param> /// <remarks>This is a thin wrapper to the native code that still handles Open IFC. This should be eventually obsoleted.</remarks> public static void Import(ImporterIFC importer) { IFCFile ifcFile = null; try { IFCSchemaVersion schemaVersion = IFCSchemaVersion.IFC2x3; ifcFile = CreateIFCFile(importer.FullFileName, out schemaVersion); IFCFileReadOptions readOptions = new IFCFileReadOptions(); readOptions.FileName = importer.FullFileName; readOptions.XMLConfigFileName = Path.Combine(DirectoryUtil.RevitProgramPath, "EDM\\ifcXMLconfiguration.xml"); ifcFile.Read(readOptions); importer.SetFile(ifcFile); //If there is more than one project, we will be ignoring all but the first one. IList <IFCAnyHandle> projects = ifcFile.GetInstances(IFCAnyHandleUtil.GetIFCEntityTypeName(IFCEntityType.IfcProject), false); if (projects.Count == 0) { throw new InvalidOperationException("Failed to import IFC to Revit."); } IFCAnyHandle project = projects[0]; importer.ProcessIFCProject(project); StoreIFCCreatorInfo(ifcFile, importer.Document.ProjectInformation); } finally { if (ifcFile != null) { ifcFile.Close(); ifcFile = null; } } }
private bool Process(string ifcFilePath, IFCImportOptions options, Document doc) { // Manually set to false if necessary for debugging. CleanEntitiesAfterCreate = true; TheFileName = ifcFilePath; TheBrepCounter = 0; Log = IFCImportLog.CreateLog(ifcFilePath + ".log.html"); try { IFCSchemaVersion schemaVersion; m_IfcFile = CreateIFCFile(ifcFilePath, out schemaVersion); SchemaVersion = schemaVersion; } catch (Exception ex) { Log.LogError(-1, "There was an error reading the IFC file: " + ex.Message + ". Aborting import.", false); return false; } Options = options; Document = doc; ShapeLibrary = DirectShapeLibrary.GetDirectShapeLibrary(doc); ShapeLibrary.Reset(); IFCFileReadOptions readOptions = new IFCFileReadOptions(); readOptions.FileName = ifcFilePath; readOptions.XMLConfigFileName = Path.Combine(RevitProgramPath, "EDM\\ifcXMLconfiguration.xml"); int numErrors = 0; int numWarnings = 0; try { Importer.TheCache.StatusBar.Set(String.Format(Resources.IFCReadingFile, TheFileName)); m_IfcFile.Read(readOptions, out numErrors, out numWarnings); } catch (Exception ex) { Log.LogError(-1, "There was an error reading the IFC file: " + ex.Message + ". Aborting import.", false); return false; } if (numErrors > 0 || numWarnings > 0) { if (numErrors > 0) { if (numWarnings > 0) Log.LogError(-1, "There were " + numErrors + " errors and " + numWarnings + " reading the IFC file. Please look at the log information at the end of this report for more information.", false); else Log.LogError(-1, "There were " + numErrors + " errors reading the IFC file. Please look at the log information at the end of this report for more information.", false); } else { Log.LogWarning(-1, "There were " + numWarnings + " warnings reading the IFC file. Please look at the log information at the end of this report for more information.", false); } } m_Transaction = new Transaction(doc); switch (options.Intent) { case IFCImportIntent.Reference: InitializeOpenTransaction("Open IFC Reference File"); //If there is more than one project, we will be ignoring all but the first one. IList<IFCAnyHandle> projects = IFCImportFile.TheFile.GetInstances(IFCEntityType.IfcProject, false); if (projects.Count == 0) { Log.LogError(-1, "There were no IfcProjects found in the file. Aborting import.", false); return false; } else IFCProject.ProcessIFCProject(projects[0]); break; } return true; }
private bool Process(string ifcFilePath, IFCImportOptions options, Document doc) { // Manually set to false if necessary for debugging. CleanEntitiesAfterCreate = true; TheFileName = ifcFilePath; TheBrepCounter = 0; Log = IFCImportLog.CreateLog(ifcFilePath + ".log.html"); try { IFCSchemaVersion schemaVersion; m_IfcFile = CreateIFCFile(ifcFilePath, out schemaVersion); SchemaVersion = schemaVersion; } catch (Exception ex) { Log.LogError(-1, "There was an error reading the IFC file: " + ex.Message + ". Aborting import.", false); return(false); } Options = options; Document = doc; ShapeLibrary = DirectShapeLibrary.GetDirectShapeLibrary(doc); ShapeLibrary.Reset(); IFCFileReadOptions readOptions = new IFCFileReadOptions(); readOptions.FileName = ifcFilePath; readOptions.XMLConfigFileName = Path.Combine(RevitProgramPath, "EDM\\ifcXMLconfiguration.xml"); int numErrors = 0; int numWarnings = 0; try { Importer.TheCache.StatusBar.Set(String.Format(Resources.IFCReadingFile, TheFileName)); m_IfcFile.Read(readOptions, out numErrors, out numWarnings); } catch (Exception ex) { Log.LogError(-1, "There was an error reading the IFC file: " + ex.Message + ". Aborting import.", false); return(false); } if (numErrors > 0 || numWarnings > 0) { if (numErrors > 0) { if (numWarnings > 0) { Log.LogError(-1, "There were " + numErrors + " errors and " + numWarnings + " reading the IFC file. Please look at the log information at the end of this report for more information.", false); } else { Log.LogError(-1, "There were " + numErrors + " errors reading the IFC file. Please look at the log information at the end of this report for more information.", false); } } else { Log.LogWarning(-1, "There were " + numWarnings + " warnings reading the IFC file. Please look at the log information at the end of this report for more information.", false); } } m_Transaction = new Transaction(doc); switch (options.Intent) { case IFCImportIntent.Reference: InitializeOpenTransaction("Open IFC Reference File"); //If there is more than one project, we will be ignoring all but the first one. IList <IFCAnyHandle> projects = IFCImportFile.TheFile.GetInstances(IFCEntityType.IfcProject, false); if (projects.Count == 0) { Log.LogError(-1, "There were no IfcProjects found in the file. Aborting import.", false); return(false); } else { IFCProject.ProcessIFCProject(projects[0]); } break; } return(true); }