/// <summary> /// Processes IfcObject handle. /// </summary> /// <param name="ifcObject">The IfcObject handle.</param> /// <returns>The IfcObject object.</returns> public static IFCObject ProcessIFCObject(IFCAnyHandle ifcObject) { if (IFCAnyHandleUtil.IsNullOrHasNoValue(ifcObject)) { IFCImportFile.TheLog.LogNullError(IFCEntityType.IfcObject); return(null); } IFCEntity cachedObject; if (IFCImportFile.TheFile.EntityMap.TryGetValue(ifcObject.StepId, out cachedObject)) { return(cachedObject as IFCObject); } if (IFCAnyHandleUtil.IsSubTypeOf(ifcObject, IFCEntityType.IfcProduct)) { return(IFCProduct.ProcessIFCProduct(ifcObject)); } else if (IFCAnyHandleUtil.IsSubTypeOf(ifcObject, IFCEntityType.IfcProject)) { return(IFCProject.ProcessIFCProject(ifcObject)); } IFCImportFile.TheLog.LogUnhandledSubTypeError(ifcObject, IFCEntityType.IfcObject, true); return(null); }
/// <summary> /// Top-level function that processes an IFC file for reference. /// </summary> /// <returns>True if the process is successful, false otherwise.</returns> private bool ProcessReference() { 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) { Importer.TheLog.LogError(-1, "There were no IfcProjects found in the file. Aborting import.", false); return(false); } IFCProject.ProcessIFCProject(projects[0]); // The IFC toolkit relies on the IFC schema definition to read in the file. The schema definition has entities that have data fields, // and INVERSE relationships. Unfortunately, the standard IFC 2x3 schema has a "bug" where one of the inverse relationships is missing. // Normally we don't care all that much, but now we do. So if we don't allow using this inverse (because if we did, it would just constantly // throw exceptions), we need another way to get the zones. This is the way. // We are also using this to find IfcSystems that don't have the optional IfcRelServicesBuildings set. if (!IFCImportFile.TheFile.Options.AllowUseHasAssignments) { IList <IFCAnyHandle> zones = IFCImportFile.TheFile.GetInstances(IFCEntityType.IfcZone, false); foreach (IFCAnyHandle zone in zones) { IFCZone ifcZone = IFCZone.ProcessIFCZone(zone); if (ifcZone != null) { OtherEntitiesToCreate.Add(ifcZone); } } IList <IFCAnyHandle> systems = IFCImportFile.TheFile.GetInstances(IFCEntityType.IfcSystem, false); foreach (IFCAnyHandle system in systems) { IFCSystem ifcSystem = IFCSystem.ProcessIFCSystem(system); if (ifcSystem != null) { OtherEntitiesToCreate.Add(ifcSystem); } } } return(PostProcessReference()); }
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); }