/// <summary> /// Exports spatial elements, including rooms, areas and spaces. 2nd level space boundaries. /// </summary> /// <param name="ifcExporter"> /// The Exporter object. /// </param> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="document"> /// The Revit document. /// </param> /// <param name="filterView"> /// The view not exported. /// </param> /// <param name="spaceExported"> /// The output boolean value indicates if exported successfully. /// </param> public static void ExportSpatialElement2ndLevel(BIM.IFC.Exporter.Exporter ifcExporter, ExporterIFC exporterIFC, Document document, View filterView, ref bool spaceExported) { using (SubTransaction st = new SubTransaction(document)) { st.Start(); EnergyAnalysisDetailModel model = null; try { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(file)) { EnergyAnalysisDetailModelOptions options = new EnergyAnalysisDetailModelOptions(); options.Tier = EnergyAnalysisDetailModelTier.SecondLevelBoundaries; //2nd level space boundaries options.SimplifyCurtainSystems = true; try { model = EnergyAnalysisDetailModel.Create(document, options); } catch (System.Exception) { spaceExported = false; return; } IList<EnergyAnalysisSpace> spaces = model.GetAnalyticalSpaces(); spaceExported = true; foreach (EnergyAnalysisSpace space in spaces) { SpatialElement spatialElement = document.GetElement(space.SpatialElementId) as SpatialElement; if (spatialElement == null) continue; //quick reject bool isArea = spatialElement is Area; if (isArea) { if (!IsAreaGrossInterior(exporterIFC, spatialElement)) continue; } //current view only if (filterView != null && !ElementFilteringUtil.IsElementVisible(filterView, spatialElement)) continue; // if (!ElementFilteringUtil.ShouldCategoryBeExported(exporterIFC, spatialElement)) continue; Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); View ownerView = spatialElement.Document.GetElement(spatialElement.OwnerViewId) as View; if (ownerView != null) geomOptions.View = ownerView; GeometryElement geomElem = spatialElement.get_Geometry(geomOptions); try { exporterIFC.PushExportState(spatialElement, geomElem); using (ProductWrapper productWrapper = ProductWrapper.Create(exporterIFC, true)) { ElementId levelId = spatialElement.Level != null ? spatialElement.Level.Id : ElementId.InvalidElementId; using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, spatialElement, null, null, levelId)) { if (!CreateIFCSpace(exporterIFC, spatialElement, productWrapper, setter)) continue; XYZ offset = GetSapceBoundaryOffset(setter); //get boundary information from surfaces IList<EnergyAnalysisSurface> surfaces = space.GetAnalyticalSurfaces(); foreach (EnergyAnalysisSurface surface in surfaces) { Element boundingElement = GetBoundaryElement(document, surface.OriginatingElementId); IList<EnergyAnalysisOpening> openings = surface.GetAnalyticalOpenings(); IFCAnyHandle connectionGeometry = CreateConnectionSurfaceGeometry(file, surface, openings, offset); CreateIFCSpaceBoundary(file, exporterIFC, spatialElement, boundingElement, setter.LevelId, connectionGeometry); // try to add doors and windows for host objects if appropriate. if (boundingElement is HostObject) { foreach (EnergyAnalysisOpening opening in openings) { Element openingBoundingElem = GetBoundaryElement(document, opening.OriginatingElementId); IFCAnyHandle openingConnectionGeom = CreateConnectionSurfaceGeometry(file, opening, offset); CreateIFCSpaceBoundary(file, exporterIFC, spatialElement, openingBoundingElem, setter.LevelId, openingConnectionGeom); } } } PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, spatialElement, productWrapper); CreateZoneInfos(exporterIFC, file, spatialElement, productWrapper); CreateSpaceOccupantInfo(exporterIFC, file, spatialElement, productWrapper); ifcExporter.ExportElementProperties(exporterIFC, spatialElement, productWrapper); ifcExporter.ExportElementQuantities(exporterIFC, spatialElement, productWrapper); } } } catch (Exception ex) { ifcExporter.HandleUnexpectedException(ex, exporterIFC, spatialElement); } finally { exporterIFC.PopExportState(); } } transaction.Commit(); } } finally { if (model != null) EnergyAnalysisDetailModel.Destroy(model); } st.RollBack(); } }