/// <summary> /// Initializes the common properties at the beginning of the export process. /// </summary> /// <param name="exporterIFC">The IFC exporter object.</param> /// <param name="document">The document to export.</param> private void BeginExport(ExporterIFC exporterIFC, Document document, Autodesk.Revit.DB.View filterView) { // cache options ExportOptionsCache exportOptionsCache = ExportOptionsCache.Create(exporterIFC, filterView); ExporterCacheManager.ExportOptionsCache = exportOptionsCache; // Set language. Application app = document.Application; string pathName = document.PathName; LanguageType langType = LanguageType.Unknown; if (!String.IsNullOrEmpty(pathName)) { try { BasicFileInfo basicFileInfo = BasicFileInfo.Extract(pathName); if (basicFileInfo != null) langType = basicFileInfo.LanguageWhenSaved; } catch { } } if (langType == LanguageType.Unknown) langType = app.Language; ExporterCacheManager.LanguageType = langType; ElementFilteringUtil.InitCategoryVisibilityCache(); ExporterCacheManager.Document = document; String writeIFCExportedElementsVar = Environment.GetEnvironmentVariable("WriteIFCExportedElements"); if (writeIFCExportedElementsVar != null && writeIFCExportedElementsVar.Length > 0) { m_Writer = new StreamWriter(@"c:\ifc-output-filters.txt"); } IFCFileModelOptions modelOptions = CreateIFCFileModelOptions(exporterIFC); m_IfcFile = IFCFile.Create(modelOptions); exporterIFC.SetFile(m_IfcFile); //init common properties InitializePropertySets(ExporterCacheManager.ExportOptionsCache.FileVersion); InitializeQuantities(ExporterCacheManager.ExportOptionsCache.FileVersion); IFCFile file = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(file)) { // create building IFCAnyHandle applicationHandle = CreateApplicationInformation(file, document); CreateGlobalCartesianOrigin(exporterIFC); CreateGlobalDirection(exporterIFC); CreateGlobalDirection2D(exporterIFC); // Start out relative to nothing, but replace with site later. IFCAnyHandle relativePlacement = ExporterUtil.CreateAxis2Placement3D(file); IFCAnyHandle buildingPlacement = IFCInstanceExporter.CreateLocalPlacement(file, null, relativePlacement); CreateProject(exporterIFC, document, applicationHandle); IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle(); ProjectInfo projInfo = document.ProjectInformation; string buildingName = String.Empty; if (projInfo != null) { try { buildingName = projInfo.BuildingName; } catch (Autodesk.Revit.Exceptions.InvalidOperationException) { } } IFCAnyHandle buildingAddress = CreateIFCAddress(file, document, projInfo); IFCAnyHandle buildingHandle = IFCInstanceExporter.CreateBuilding(file, GUIDUtil.CreateProjectLevelGUID(document, IFCProjectLevelGUIDType.Building), ownerHistory, buildingName, null, null, buildingPlacement, null, buildingName, Toolkit.IFCElementComposition.Element, null, null, buildingAddress); exporterIFC.SetBuilding(buildingHandle); // create levels List<Level> levels = LevelUtil.FindAllLevels(document); bool exportAllLevels = true; for (int ii = 0; ii < levels.Count && exportAllLevels; ii++) { Level level = levels[ii]; Parameter isBuildingStorey = level.get_Parameter(BuiltInParameter.LEVEL_IS_BUILDING_STORY); if (isBuildingStorey == null || (isBuildingStorey.AsInteger() != 0)) { exportAllLevels = false; break; } } IList<Element> unassignedBaseLevels = new List<Element>(); ExporterCacheManager.ExportOptionsCache.ExportAllLevels = exportAllLevels; double scaleFactor = exporterIFC.LinearScale; IFCAnyHandle prevBuildingStorey = null; IFCAnyHandle prevPlacement = null; double prevHeight = 0.0; double prevElev = 0.0; for (int ii = 0; ii < levels.Count; ii++) { Level level = levels[ii]; if (level == null) continue; IFCLevelInfo levelInfo = null; if (!LevelUtil.IsBuildingStory(level)) { if (prevBuildingStorey == null) unassignedBaseLevels.Add(level); else { levelInfo = IFCLevelInfo.Create(prevBuildingStorey, prevPlacement, prevHeight, prevElev, scaleFactor, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo); } continue; } // When exporting to IFC 2x3, we have a limited capability to export some Revit view-specific // elements, specifically Filled Regions and Text. However, we do not have the // capability to choose which views to export. As such, we will choose (up to) one DBView per // exported level. // TODO: Let user choose which view(s) to export. Ensure that the user know that only one view // per level is supported. View view = LevelUtil.FindViewByLevel(document, ViewType.FloorPlan, level); if (view != null) { exporterIFC.AddViewIdToExport(view.Id, level.Id); } double elev = level.ProjectElevation; double height = 0.0; List<ElementId> coincidentLevels = new List<ElementId>(); for (int jj = ii + 1; jj < levels.Count; jj++) { Level nextLevel = levels[jj]; if (!LevelUtil.IsBuildingStory(nextLevel)) continue; double nextElev = nextLevel.ProjectElevation; if (!MathUtil.IsAlmostEqual(nextElev, elev)) { height = nextElev - elev; break; } else if (ExporterCacheManager.ExportOptionsCache.WallAndColumnSplitting) coincidentLevels.Add(nextLevel.Id); } double elevation = elev * scaleFactor; XYZ orig = new XYZ(0.0, 0.0, elevation); IFCAnyHandle axis2Placement3D = ExporterUtil.CreateAxis2Placement3D(file, orig); IFCAnyHandle placement = IFCInstanceExporter.CreateLocalPlacement(file, buildingPlacement, axis2Placement3D); string levelName = level.Name; string levelGUID = GUIDUtil.GetLevelGUID(level); IFCAnyHandle buildingStorey = IFCInstanceExporter.CreateBuildingStorey(file, levelGUID, exporterIFC.GetOwnerHistoryHandle(), levelName, null, null, placement, null, levelName, Toolkit.IFCElementComposition.Element, elevation); // If we are using the R2009 Level GUIDs, write it to a shared paramter in the file to ensure that it is preserved. if (ExporterCacheManager.ExportOptionsCache.GUIDOptions.Use2009BuildingStoreyGUIDs) { string oldLevelGUID; ParameterUtil.GetStringValueFromElement(level, BuiltInParameter.IFC_GUID, out oldLevelGUID); if (String.IsNullOrEmpty(oldLevelGUID)) { ParameterUtil.SetStringParameter(level, BuiltInParameter.IFC_GUID, levelGUID); } } if (prevBuildingStorey == null) { foreach (Level baseLevel in unassignedBaseLevels) { levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, scaleFactor, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, baseLevel.Id, levelInfo); } } prevBuildingStorey = buildingStorey; prevPlacement = placement; prevHeight = height; prevElev = elev; levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, scaleFactor, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo); // if we have coincident levels, add buildingstoreys for them but use the old handle. for (int jj = 0; jj < coincidentLevels.Count; jj++) { level = levels[ii + jj + 1]; levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, scaleFactor, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo); } ii += coincidentLevels.Count; using (ProductWrapper productWrapper = ProductWrapper.Create(exporterIFC, false)) { // Add Property set, quantities and classification of Building Storey also to IFC productWrapper.AddElement(levelInfo.GetBuildingStorey(), levelInfo, null, false); // Create Quantities (if set) and Classification for Levels (Building Stories) here // ExportElementProperties(exporterIFC, level, productWrapper); // PSet creation is done somewhere else (?), so skip it here if (ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities && !(ExporterCacheManager.ExportOptionsCache.FileVersion == IFCVersion.IFCCOBIE)) ExportElementQuantities(exporterIFC, level, productWrapper); ExportElementClassifications(exporterIFC, level, productWrapper); } } transaction.Commit(); } }
/// <summary> /// Initializes the common properties at the beginning of the export process. /// </summary> /// <param name="exporterIFC">The IFC exporter object.</param> /// <param name="document">The document to export.</param> private void BeginExport(ExporterIFC exporterIFC, Document document, Autodesk.Revit.DB.View filterView) { // cache options ExportOptionsCache exportOptionsCache = ExportOptionsCache.Create(exporterIFC, document, filterView); ExporterCacheManager.ExportOptionsCache = exportOptionsCache; // Set language. Application app = document.Application; string pathName = document.PathName; LanguageType langType = LanguageType.Unknown; if (!String.IsNullOrEmpty(pathName)) { try { BasicFileInfo basicFileInfo = BasicFileInfo.Extract(pathName); if (basicFileInfo != null) langType = basicFileInfo.LanguageWhenSaved; } catch { } } if (langType == LanguageType.Unknown) langType = app.Language; ExporterCacheManager.LanguageType = langType; ElementFilteringUtil.InitCategoryVisibilityCache(); ExporterCacheManager.Document = document; String writeIFCExportedElementsVar = Environment.GetEnvironmentVariable("WriteIFCExportedElements"); if (writeIFCExportedElementsVar != null && writeIFCExportedElementsVar.Length > 0) { m_Writer = new StreamWriter(@"c:\ifc-output-filters.txt"); } IFCFileModelOptions modelOptions = CreateIFCFileModelOptions(exporterIFC); m_IfcFile = IFCFile.Create(modelOptions); exporterIFC.SetFile(m_IfcFile); //init common properties InitializePropertySets(ExporterCacheManager.ExportOptionsCache.FileVersion); InitializeQuantities(ExporterCacheManager.ExportOptionsCache.FileVersion); IFCFile file = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(file)) { // create building IFCAnyHandle applicationHandle = CreateApplicationInformation(file, document); CreateGlobalCartesianOrigin(exporterIFC); CreateGlobalDirection(exporterIFC); CreateGlobalDirection2D(exporterIFC); // Set relative transform depending on whether it is a linked transform or not. IFCAnyHandle relativePlacement = null; if (ExporterCacheManager.ExportOptionsCache.ExportingLink) { Transform linkTrf = ExporterCacheManager.ExportOptionsCache.GetLinkInstanceTransform(0); relativePlacement = ExporterUtil.CreateAxis2Placement3D(file, linkTrf.Origin, linkTrf.BasisZ, linkTrf.BasisX); } else relativePlacement = ExporterUtil.CreateAxis2Placement3D(file); IFCAnyHandle buildingPlacement = IFCInstanceExporter.CreateLocalPlacement(file, null, relativePlacement); CreateProject(exporterIFC, document, applicationHandle); IFCAnyHandle ownerHistory = exporterIFC.GetOwnerHistoryHandle(); ProjectInfo projectInfo = document.ProjectInformation; string buildingName = String.Empty; string buildingDescription = null; string buildingLongName = null; if (projectInfo != null) { try { buildingName = projectInfo.BuildingName; } catch (Autodesk.Revit.Exceptions.InvalidOperationException) { } buildingDescription = NamingUtil.GetOverrideStringValue(projectInfo, "BuildingDescription", null); buildingLongName = NamingUtil.GetOverrideStringValue(projectInfo, "BuildingLongName", buildingName); } IFCAnyHandle buildingAddress = CreateIFCAddress(file, document, projectInfo); string buildingGUID = GUIDUtil.CreateProjectLevelGUID(document, IFCProjectLevelGUIDType.Building); IFCAnyHandle buildingHandle = IFCInstanceExporter.CreateBuilding(file, buildingGUID, ownerHistory, buildingName, buildingDescription, null, buildingPlacement, null, buildingLongName, Toolkit.IFCElementComposition.Element, null, null, buildingAddress); ExporterCacheManager.BuildingHandle = buildingHandle; // create levels List<Level> levels = LevelUtil.FindAllLevels(document); bool exportAllLevels = true; for (int ii = 0; ii < levels.Count && exportAllLevels; ii++) { Level level = levels[ii]; Parameter isBuildingStorey = level.get_Parameter(BuiltInParameter.LEVEL_IS_BUILDING_STORY); if (isBuildingStorey == null || (isBuildingStorey.AsInteger() != 0)) { exportAllLevels = false; break; } } IList<Element> unassignedBaseLevels = new List<Element>(); ExporterCacheManager.ExportOptionsCache.ExportAllLevels = exportAllLevels; double lengthScale = UnitUtil.ScaleLengthForRevitAPI(); IFCAnyHandle prevBuildingStorey = null; IFCAnyHandle prevPlacement = null; double prevHeight = 0.0; double prevElev = 0.0; for (int ii = 0; ii < levels.Count; ii++) { Level level = levels[ii]; if (level == null) continue; IFCLevelInfo levelInfo = null; if (!LevelUtil.IsBuildingStory(level)) { if (prevBuildingStorey == null) unassignedBaseLevels.Add(level); else { levelInfo = IFCLevelInfo.Create(prevBuildingStorey, prevPlacement, prevHeight, prevElev, lengthScale, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo, false); } continue; } // When exporting to IFC 2x3, we have a limited capability to export some Revit view-specific // elements, specifically Filled Regions and Text. However, we do not have the // capability to choose which views to export. As such, we will choose (up to) one DBView per // exported level. // TODO: Let user choose which view(s) to export. Ensure that the user know that only one view // per level is supported. View view = LevelUtil.FindViewByLevel(document, ViewType.FloorPlan, level); if (view != null) { ExporterCacheManager.DBViewsToExport[view.Id] = level.Id; } double elev = level.ProjectElevation; double height = 0.0; List<ElementId> coincidentLevels = new List<ElementId>(); for (int jj = ii + 1; jj < levels.Count; jj++) { Level nextLevel = levels[jj]; if (!LevelUtil.IsBuildingStory(nextLevel)) continue; double nextElev = nextLevel.ProjectElevation; if (!MathUtil.IsAlmostEqual(nextElev, elev)) { height = nextElev - elev; break; } else if (ExporterCacheManager.ExportOptionsCache.WallAndColumnSplitting) coincidentLevels.Add(nextLevel.Id); } double elevation = UnitUtil.ScaleLength(elev); XYZ orig = new XYZ(0.0, 0.0, elevation); IFCAnyHandle placement = ExporterUtil.CreateLocalPlacement(file, buildingPlacement, orig, null, null); string levelName = NamingUtil.GetNameOverride(level, level.Name); string objectType = NamingUtil.GetObjectTypeOverride(level, null); string description = NamingUtil.GetDescriptionOverride(level, null); string longName = level.Name; string levelGUID = GUIDUtil.GetLevelGUID(level); IFCAnyHandle buildingStorey = IFCInstanceExporter.CreateBuildingStorey(file, levelGUID, exporterIFC.GetOwnerHistoryHandle(), levelName, description, objectType, placement, null, longName, Toolkit.IFCElementComposition.Element, elevation); // Create classification reference when level has classification filed name assigned to it ClassificationUtil.CreateClassification(exporterIFC, file, level, buildingStorey); if (prevBuildingStorey == null) { foreach (Level baseLevel in unassignedBaseLevels) { levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, lengthScale, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, baseLevel.Id, levelInfo, false); } } prevBuildingStorey = buildingStorey; prevPlacement = placement; prevHeight = height; prevElev = elev; levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, lengthScale, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo, true); // if we have coincident levels, add buildingstoreys for them but use the old handle. for (int jj = 0; jj < coincidentLevels.Count; jj++) { level = levels[ii + jj + 1]; levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, lengthScale, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo, true); } ii += coincidentLevels.Count; // We will export element properties, quantities and classifications when we decide to keep the level - we may delete it later. } transaction.Commit(); } }
/// <summary> /// Initializes the common properties at the beginning of the export process. /// </summary> /// <param name="exporterIFC">The IFC exporter object.</param> /// <param name="document">The document to export.</param> private void BeginExport(ExporterIFC exporterIFC, Document document) { ExporterCacheManager.Document = document; String writeIFCExportedElementsVar = Environment.GetEnvironmentVariable("WriteIFCExportedElements"); if (writeIFCExportedElementsVar != null && writeIFCExportedElementsVar.Length > 0) { m_Writer = new StreamWriter(@"c:\ifc-output-filters.txt"); } IFCFileModelOptions modelOptions = new IFCFileModelOptions(); if (exporterIFC.ExportAs2x2) { modelOptions.SchemaFile = Path.Combine(ExporterUtil.RevitProgramPath, "EDM\\IFC2X2_ADD1.exp"); modelOptions.SchemaName = "IFC2x2_FINAL"; } else { modelOptions.SchemaFile = Path.Combine(ExporterUtil.RevitProgramPath, "EDM\\IFC2X3_TC1.exp"); modelOptions.SchemaName = "IFC2x3"; } m_IfcFile = IFCFile.Create(modelOptions); exporterIFC.SetFile(m_IfcFile); //init common properties ExporterInitializer.InitPropertySets(ExporterCacheManager.ExportOptionsCache.FileVersion); ExporterInitializer.InitQuantities(ExporterCacheManager.ExportOptionsCache.FileVersion, ExporterCacheManager.ExportOptionsCache.ExportBaseQuantities); IFCFile file = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(file)) { // create building IFCAnyHandle applicationHandle = CreateApplicationInformation(file, document.Application); CreateGlobalCartesianOrigin(exporterIFC); CreateGlobalDirection(exporterIFC); CreateGlobalDirection2D(exporterIFC); IFCAnyHandle units = CreateDefaultUnits(exporterIFC, document); // Start out relative to nothing, but replace with site later. IFCAnyHandle relativePlacement = ExporterUtil.CreateAxis2Placement3D(file); IFCAnyHandle buildingPlacement = IFCInstanceExporter.CreateLocalPlacement(file, null, relativePlacement); HashSet<IFCAnyHandle> repContexts = CreateContextInformation(exporterIFC, document); IFCAnyHandle ownerHistory = CreateGenericOwnerHistory(exporterIFC, document, applicationHandle); exporterIFC.SetOwnerHistoryHandle(ownerHistory); IFCAnyHandle projectHandle = IFCInstanceExporter.CreateProject(file, ExporterIFCUtils.CreateProjectLevelGUID(document, IFCProjectLevelGUIDType.Project), ownerHistory, null, null, null, null, null, repContexts, units); exporterIFC.SetProject(projectHandle); ProjectInfo projInfo = document.ProjectInformation; string projectAddress = projInfo != null ? projInfo.Address : String.Empty; SiteLocation siteLoc = document.ActiveProjectLocation.SiteLocation; string location = siteLoc != null ? siteLoc.PlaceName : String.Empty; if (projectAddress == null) projectAddress = String.Empty; if (location == null) location = String.Empty; IFCAnyHandle buildingAddress = CreateIFCAddress(file, projectAddress, location); string buildingName = String.Empty; if (projInfo != null) { try { buildingName = projInfo.BuildingName; } catch (Autodesk.Revit.Exceptions.InvalidOperationException) { } } IFCAnyHandle buildingHandle = IFCInstanceExporter.CreateBuilding(file, ExporterIFCUtils.CreateProjectLevelGUID(document, IFCProjectLevelGUIDType.Building), ownerHistory, buildingName, null, null, buildingPlacement, null, buildingName, Toolkit.IFCElementComposition.Element, null, null, buildingAddress); exporterIFC.SetBuilding(buildingHandle); // create levels List<Level> levels = LevelUtil.FindAllLevels(document); bool exportAllLevels = true; for (int ii = 0; ii < levels.Count && exportAllLevels; ii++) { Level level = levels[ii]; Parameter isBuildingStorey = level.get_Parameter(BuiltInParameter.LEVEL_IS_BUILDING_STORY); if (isBuildingStorey == null || (isBuildingStorey.AsInteger() != 0)) { exportAllLevels = false; break; } } IList<Element> unassignedBaseLevels = new List<Element>(); ExporterCacheManager.ExportOptionsCache.ExportAllLevels = exportAllLevels; double scaleFactor = exporterIFC.LinearScale; IFCAnyHandle prevBuildingStorey = null; IFCAnyHandle prevPlacement = null; double prevHeight = 0.0; double prevElev = 0.0; for (int ii = 0; ii < levels.Count; ii++) { Level level = levels[ii]; if (level == null) continue; IFCLevelInfo levelInfo = null; if (!LevelUtil.IsBuildingStory(level)) { if (prevBuildingStorey == null) unassignedBaseLevels.Add(level); else { levelInfo = IFCLevelInfo.Create(prevBuildingStorey, prevPlacement, prevHeight, prevElev, scaleFactor, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo); } continue; } // When exporting to IFC 2x3, we have a limited capability to export some Revit view-specific // elements, specifically Filled Regions and Text. However, we do not have the // capability to choose which views to export. As such, we will choose (up to) one DBView per // exported level. // TODO: Let user choose which view(s) to export. Ensure that the user know that only one view // per level is supported. View view = LevelUtil.FindViewByLevel(document, ViewType.FloorPlan, level); if (view != null) { exporterIFC.AddViewIdToExport(view.Id, level.Id); } double elev = level.ProjectElevation; double height = 0.0; List<ElementId> coincidentLevels = new List<ElementId>(); for (int jj = ii+1; jj < levels.Count; jj++) { Level nextLevel = levels[jj]; if (!LevelUtil.IsBuildingStory(nextLevel)) continue; double nextElev = nextLevel.ProjectElevation; if (!MathUtil.IsAlmostEqual(nextElev, elev)) { height = nextElev - elev; break; } else if (ExporterCacheManager.ExportOptionsCache.WallAndColumnSplitting) coincidentLevels.Add(nextLevel.Id); } double elevation = elev * scaleFactor; XYZ orig = new XYZ(0.0, 0.0, elevation); IFCAnyHandle axis2Placement3D = ExporterUtil.CreateAxis2Placement3D(file, orig); IFCAnyHandle placement = IFCInstanceExporter.CreateLocalPlacement(file, buildingPlacement, axis2Placement3D); string levelName = level.Name; string levelGUID = LevelUtil.GetLevelGUID(level); IFCAnyHandle buildingStorey = IFCInstanceExporter.CreateBuildingStorey(file, levelGUID, exporterIFC.GetOwnerHistoryHandle(), levelName, null, null, placement, null, levelName, Toolkit.IFCElementComposition.Element, elevation); // If we are using the R2009 Level GUIDs, write it to a shared paramter in the file to ensure that it is preserved. if (ExporterCacheManager.ExportOptionsCache.Use2009BuildingStoreyGUIDs) { string oldLevelGUID; ParameterUtil.GetStringValueFromElement(level, BuiltInParameter.IFC_GUID, out oldLevelGUID); if (String.IsNullOrEmpty(oldLevelGUID)) { ParameterUtil.SetStringParameter(level, BuiltInParameter.IFC_GUID, levelGUID); } } if (prevBuildingStorey == null) { foreach (Level baseLevel in unassignedBaseLevels) { levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, scaleFactor, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, baseLevel.Id, levelInfo); } } prevBuildingStorey = buildingStorey; prevPlacement = placement; prevHeight = height; prevElev = elev; levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, scaleFactor, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo); // if we have coincident levels, add buildingstoreys for them but use the old handle. for (int jj = 0; jj < coincidentLevels.Count; jj++) { level = levels[ii + jj + 1]; levelInfo = IFCLevelInfo.Create(buildingStorey, placement, height, elev, scaleFactor, true); ExporterCacheManager.LevelInfoCache.AddLevelInfo(exporterIFC, level.Id, levelInfo); } ii += coincidentLevels.Count; } transaction.Commit(); } }