/// <summary> /// Exports a hosted weep. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="hostedSweep">The hosted sweep element.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void Export(ExporterIFC exporterIFC, HostedSweep hostedSweep, GeometryElement geometryElement, ProductWrapper productWrapper) { ElementId catId = CategoryUtil.GetSafeCategoryId(hostedSweep); if (catId == new ElementId(BuiltInCategory.OST_Gutter)) { ExportGutter(exporterIFC, hostedSweep, geometryElement, productWrapper); } else { ProxyElementExporter.Export(exporterIFC, hostedSweep, geometryElement, productWrapper); } }
/// <summary> /// Exports a wall swepp. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="wallSweep">The WallSweep.</param> /// <param name="geometryElement">The geometry element.</param> /// <param name="productWrapper">The ProductWrapper.</param> public static void Export(ExporterIFC exporterIFC, WallSweep wallSweep, GeometryElement geometryElement, ProductWrapper productWrapper) { WallSweepInfo wallSweepInfo = wallSweep.GetWallSweepInfo(); //Reveals are exported as openings with wall exporter. if (wallSweepInfo.WallSweepType == WallSweepType.Reveal) { return; } if (!ProxyElementExporter.Export(exporterIFC, wallSweep, geometryElement, productWrapper)) { return; } HostObjectExporter.ExportHostObjectMaterials(exporterIFC, wallSweep, productWrapper.GetAnElement(), geometryElement, productWrapper, ElementId.InvalidElementId, Toolkit.IFCLayerSetDirection.Axis2, null); }
/// <summary> /// Exports curtain object as container. /// </summary> /// <param name="allSubElements"> /// Collection of elements contained in the host curtain element. /// </param> /// <param name="wallElement"> /// The curtain wall element. /// </param> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="productWrapper"> /// The ProductWrapper. /// </param> public static void ExportCurtainObjectCommonAsContainer(ICollection <ElementId> allSubElements, Element wallElement, ExporterIFC exporterIFC, ProductWrapper origWrapper, IFCPlacementSetter currSetter) { if (wallElement == null) { return; } string overrideCADLayer = null; ParameterUtil.GetStringValueFromElementOrSymbol(wallElement, "IFCCadLayer", out overrideCADLayer); using (ExporterStateManager.CADLayerOverrideSetter layerSetter = new ExporterStateManager.CADLayerOverrideSetter(overrideCADLayer)) { HashSet <ElementId> alreadyVisited = new HashSet <ElementId>(); // just in case. Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); { foreach (ElementId subElemId in allSubElements) { using (ProductWrapper productWrapper = ProductWrapper.Create(origWrapper)) { Element subElem = wallElement.Document.GetElement(subElemId); if (subElem == null) { continue; } if (alreadyVisited.Contains(subElem.Id)) { continue; } alreadyVisited.Add(subElem.Id); // Respect element visibility settings. if (!ElementFilteringUtil.CanExportElement(exporterIFC, subElem, false) || !ElementFilteringUtil.IsElementVisible(subElem)) { continue; } GeometryElement geomElem = subElem.get_Geometry(geomOptions); if (geomElem == null) { continue; } try { if (subElem is FamilyInstance) { if (subElem is Mullion) { if (exporterIFC.ExportAs2x2) { ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper); } else { IFCAnyHandle currLocalPlacement = currSetter.GetPlacement(); MullionExporter.Export(exporterIFC, subElem as Mullion, geomElem, currLocalPlacement, currSetter, productWrapper); } } else { FamilyInstance subFamInst = subElem as FamilyInstance; string ifcEnumType; IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, subElem, out ifcEnumType); if (exportType == IFCExportType.ExportCurtainWall) { // By default, panels and mullions are set to the same category as their parent. In this case, // ask to get the exportType from the category id, since we don't want to inherit the parent class. ElementId catId = CategoryUtil.GetSafeCategoryId(subElem); exportType = ElementFilteringUtil.GetExportTypeFromCategoryId(catId, out ifcEnumType); } if (ExporterCacheManager.ExportOptionsCache.ExportAs2x2) { if ((exportType == IFCExportType.DontExport) || (exportType == IFCExportType.ExportPlateType) || (exportType == IFCExportType.ExportMemberType)) { exportType = IFCExportType.ExportBuildingElementProxyType; } } else { if (exportType == IFCExportType.DontExport) { ifcEnumType = "CURTAIN_PANEL"; exportType = IFCExportType.ExportPlateType; } } IFCAnyHandle currLocalPlacement = currSetter.GetPlacement(); using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData()) { FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem(exporterIFC, subFamInst, exportType, ifcEnumType, productWrapper, ElementId.InvalidElementId, null, currLocalPlacement); } } } else if (subElem is CurtainGridLine) { ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper); } else if (subElem is Wall) { WallExporter.ExportWall(exporterIFC, subElem, geomElem, productWrapper); } } catch (Exception ex) { if (ExporterUtil.IsFatalException(wallElement.Document, ex)) { throw ex; } continue; } } } } } }
/// <summary> /// Exports curtain object as container. /// </summary> /// <param name="allSubElements"> /// Collection of elements contained in the host curtain element. /// </param> /// <param name="wallElement"> /// The curtain wall element. /// </param> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="productWrapper"> /// The IFCProductWrapper. /// </param> public static void ExportCurtainObjectCommonAsContainer(ICollection <ElementId> allSubElements, Element wallElement, ExporterIFC exporterIFC, IFCProductWrapper origWrapper) { if (wallElement == null) { return; } HashSet <ElementId> alreadyVisited = new HashSet <ElementId>(); // just in case. Options geomOptions = GeometryUtil.GetIFCExportGeometryOptions(); { foreach (ElementId subElemId in allSubElements) { using (IFCProductWrapper productWrapper = IFCProductWrapper.Create(origWrapper)) { Element subElem = wallElement.Document.GetElement(subElemId); if (subElem == null) { continue; } GeometryElement geomElem = subElem.get_Geometry(geomOptions); if (geomElem == null) { continue; } if (alreadyVisited.Contains(subElem.Id)) { continue; } alreadyVisited.Add(subElem.Id); try { if (subElem is FamilyInstance) { if (subElem is Mullion) { if (exporterIFC.ExportAs2x2) { ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper); } else { using (IFCPlacementSetter currSetter = IFCPlacementSetter.Create(exporterIFC, wallElement)) { IFCAnyHandle currLocalPlacement = currSetter.GetPlacement(); using (IFCExtrusionCreationData extraParams = new IFCExtrusionCreationData()) { MullionExporter.Export(exporterIFC, subElem as Mullion, geomElem, currLocalPlacement, extraParams, currSetter, productWrapper); } } } } else { FamilyInstance subFamInst = subElem as FamilyInstance; string ifcEnumType; ElementId catId = CategoryUtil.GetSafeCategoryId(subElem); IFCExportType exportType = ElementFilteringUtil.GetExportTypeFromCategoryId(catId, out ifcEnumType); if (exporterIFC.ExportAs2x2) { if ((exportType == IFCExportType.DontExport) || (exportType == IFCExportType.ExportPlateType) || (exportType == IFCExportType.ExportMemberType)) { exportType = IFCExportType.ExportBuildingElementProxy; } } else { if (exportType == IFCExportType.DontExport) { ifcEnumType = "CURTAIN_PANEL"; exportType = IFCExportType.ExportPlateType; } } FamilyInstanceExporter.ExportFamilyInstanceAsMappedItem(exporterIFC, subFamInst, exportType, ifcEnumType, productWrapper, ElementId.InvalidElementId, null); } } else if (subElem is CurtainGridLine) { ProxyElementExporter.Export(exporterIFC, subElem, geomElem, productWrapper); } } catch (Exception ex) { if (ExporterUtil.IsFatalException(wallElement.Document, ex)) { throw ex; } continue; } } } } }
/// <summary> /// Exports a Rebar to IFC ReinforcingBar. /// </summary> /// <param name="exporterIFC">The ExporterIFC object.</param> /// <param name="element">The element to be exported.</param> /// <param name="productWrapper">The ProductWrapper.</param> /// <returns>The list of IfcReinforcingBar handles created.</returns> public static IList <IFCAnyHandle> ExportRebar(ExporterIFC exporterIFC, Element element, ProductWrapper productWrapper) { try { IFCFile file = exporterIFC.GetFile(); List <IFCAnyHandle> createdRebars = new List <IFCAnyHandle>(); using (IFCTransaction transaction = new IFCTransaction(file)) { using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element, null, null, ExporterUtil.GetBaseLevelIdForElement(element))) { if (element is Rebar) { GeometryElement rebarGeometry = ExporterIFCUtils.GetRebarGeometry(element as Rebar, ExporterCacheManager.ExportOptionsCache.FilterViewForExport); // only options are: Not Export, BuildingElementProxy, or ReinforcingBar/Mesh, depending on layout. // Not Export is handled previously, and ReinforcingBar vs Mesh will be determined below. string ifcEnumType; IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType); if ((exportType == IFCExportType.ExportBuildingElementProxy) || (exportType == IFCExportType.ExportBuildingElementProxyType)) { if (rebarGeometry != null) { ProxyElementExporter.ExportBuildingElementProxy(exporterIFC, element, rebarGeometry, productWrapper); transaction.Commit(); } return(null); } } IFCAnyHandle prodRep = null; double scale = exporterIFC.LinearScale; double totalBarLengthUnscale = GetRebarTotalLength(element); double volumeUnscale = GetRebarVolume(element); double totalBarLength = totalBarLengthUnscale * scale; if (MathUtil.IsAlmostZero(totalBarLength)) { return(null); } ElementId materialId = ElementId.InvalidElementId; ParameterUtil.GetElementIdValueFromElementOrSymbol(element, BuiltInParameter.MATERIAL_ID_PARAM, out materialId); Document doc = element.Document; ElementId typeId = element.GetTypeId(); RebarBarType elementType = element.Document.GetElement(element.GetTypeId()) as RebarBarType; double diameter = (elementType == null ? 1.0 / 12.0 : elementType.BarDiameter) * scale; double radius = diameter / 2.0; double longitudinalBarNominalDiameter = diameter; double longitudinalBarCrossSectionArea = (volumeUnscale / totalBarLengthUnscale) * scale * scale; double barLength = totalBarLength / GetRebarQuantity(element); IList <Curve> baseCurves = GetRebarCenterlineCurves(element, true, false, false); int numberOfBarPositions = GetNumberOfBarPositions(element); string steelGrade = NamingUtil.GetOverrideStringValue(element, "SteelGrade", null); IFCReinforcingBarRole role = GetReinforcingBarRole(NamingUtil.GetOverrideStringValue(element, "BarRole", null)); string origRebarName = NamingUtil.GetIFCName(element); string rebarDescription = NamingUtil.GetDescriptionOverride(element, null); string rebarObjectType = NamingUtil.GetObjectTypeOverride(element, NamingUtil.CreateIFCObjectName(exporterIFC, element)); string rebarElemId = NamingUtil.CreateIFCElementId(element); const int maxBarGUIDS = IFCReinforcingBarSubElements.BarEnd - IFCReinforcingBarSubElements.BarStart + 1; ElementId categoryId = CategoryUtil.GetSafeCategoryId(element); IFCAnyHandle originalPlacement = setter.GetPlacement(); for (int i = 0; i < numberOfBarPositions; i++) { if (!DoesBarExistAtPosition(element, i)) { continue; } string rebarName = NamingUtil.GetNameOverride(element, origRebarName + ": " + i); Transform barTrf = GetBarPositionTransform(element, i); IList <Curve> curves = new List <Curve>(); double endParam = 0.0; foreach (Curve baseCurve in baseCurves) { if (baseCurve is Arc || baseCurve is Ellipse) { if (baseCurve.IsBound) { endParam += (baseCurve.get_EndParameter(1) - baseCurve.get_EndParameter(0)) * 180 / Math.PI; } else { endParam += (2 * Math.PI) * 180 / Math.PI; } } else { endParam += 1.0; } curves.Add(baseCurve.get_Transformed(barTrf)); } IFCAnyHandle compositeCurve = GeometryUtil.CreateCompositeCurve(exporterIFC, curves); IFCAnyHandle sweptDiskSolid = IFCInstanceExporter.CreateSweptDiskSolid(file, compositeCurve, radius, null, 0, endParam); HashSet <IFCAnyHandle> bodyItems = new HashSet <IFCAnyHandle>(); bodyItems.Add(sweptDiskSolid); IFCAnyHandle shapeRep = RepresentationUtil.CreateAdvancedSweptSolidRep(exporterIFC, element, categoryId, exporterIFC.Get3DContextHandle("Body"), bodyItems, null); IList <IFCAnyHandle> shapeReps = new List <IFCAnyHandle>(); shapeReps.Add(shapeRep); prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps); IFCAnyHandle copyLevelPlacement = (i == 0) ? originalPlacement : ExporterUtil.CopyLocalPlacement(file, originalPlacement); string rebarGUID = (i < maxBarGUIDS) ? GUIDUtil.CreateSubElementGUID(element, i + (int)IFCReinforcingBarSubElements.BarStart) : GUIDUtil.CreateGUID(); IFCAnyHandle elemHnd = IFCInstanceExporter.CreateReinforcingBar(file, rebarGUID, exporterIFC.GetOwnerHistoryHandle(), rebarName, rebarDescription, rebarObjectType, copyLevelPlacement, prodRep, rebarElemId, steelGrade, longitudinalBarNominalDiameter, longitudinalBarCrossSectionArea, barLength, role, null); createdRebars.Add(elemHnd); productWrapper.AddElement(element, elemHnd, setter.GetLevelInfo(), null, true); ExporterCacheManager.HandleToElementCache.Register(elemHnd, element.Id); CategoryUtil.CreateMaterialAssociation(exporterIFC, elemHnd, materialId); } } transaction.Commit(); } return(createdRebars); } catch (Exception) { // It will throw exception at GetBarPositionTransform when exporting rebars with Revit 2013 UR1 and before versions, so we skip the export. // It should not come here and will export the rebars properly at Revit later versions. } return(null); }
/// <summary> /// Exports a Rebar to IFC ReinforcingMesh. /// </summary> /// <param name="exporterIFC"> /// The ExporterIFC object. /// </param> /// <param name="element"> /// The element to be exported. /// </param> /// <param name="productWrapper"> /// The IFCProductWrapper. /// </param> public static void ExportRebar(ExporterIFC exporterIFC, Rebar element, Autodesk.Revit.DB.View filterView, IFCProductWrapper productWrapper) { IFCFile file = exporterIFC.GetFile(); using (IFCTransaction transaction = new IFCTransaction(file)) { using (IFCPlacementSetter setter = IFCPlacementSetter.Create(exporterIFC, element)) { GeometryElement rebarGeometry = ExporterIFCUtils.GetRebarGeometry(element, filterView); // only options are: Not Export, BuildingElementProxy, or ReinforcingBar/Mesh, depending on layout. // Not Export is handled previously, and ReinforcingBar vs Mesh will be determined below. string ifcEnumType; IFCExportType exportType = ExporterUtil.GetExportType(exporterIFC, element, out ifcEnumType); if (exportType == IFCExportType.ExportBuildingElementProxy) { if (rebarGeometry != null) { ProxyElementExporter.ExportBuildingElementProxy(exporterIFC, element, rebarGeometry, productWrapper); transaction.Commit(); } return; } IFCAnyHandle prodRep = null; using (IFCExtrusionCreationData extrusionCreationData = new IFCExtrusionCreationData()) { extrusionCreationData.SetLocalPlacement(setter.GetPlacement()); if (rebarGeometry != null) { ElementId categoryId = CategoryUtil.GetSafeCategoryId(element); BodyExporterOptions bodyExporterOptions = new BodyExporterOptions(true); prodRep = BodyExporter.ExportBody(element.Document.Application, exporterIFC, element, categoryId, rebarGeometry, bodyExporterOptions, extrusionCreationData).RepresentationHnd; if (IFCAnyHandleUtil.IsNullOrHasNoValue(prodRep)) { extrusionCreationData.ClearOpenings(); } } double scale = exporterIFC.LinearScale; double barLength = element.TotalLength * scale; if (MathUtil.IsAlmostZero(barLength)) { return; } int quantity = element.Quantity; if (quantity < 1) { return; } ElementId typeId = element.GetTypeId(); RebarBarType elementType = element.Document.GetElement(element.GetTypeId()) as RebarBarType; double diameter = elementType == null ? 1.0 / 12.0 : elementType.BarDiameter; double longitudinalBarNominalDiameter = diameter * scale; double longitudinalBarCrossSectionArea = (element.Volume * scale * scale * scale) / barLength; string steelGradeOpt = null; IFCAnyHandle elemHnd = null; string rebarGUID = ExporterIFCUtils.CreateGUID(element); string origRebarName = exporterIFC.GetName(); string rebarName = NamingUtil.GetNameOverride(element, origRebarName); string rebarDescription = NamingUtil.GetDescriptionOverride(element, null); string rebarObjectType = NamingUtil.GetObjectTypeOverride(element, NamingUtil.CreateIFCObjectName(exporterIFC, element)); string rebarElemId = NamingUtil.CreateIFCElementId(element); if (element.LayoutRule == RebarLayoutRule.Single || (quantity == 1)) { IFCReinforcingBarRole role = IFCReinforcingBarRole.NotDefined; elemHnd = IFCInstanceExporter.CreateReinforcingBar(file, rebarGUID, exporterIFC.GetOwnerHistoryHandle(), rebarName, rebarDescription, rebarObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, rebarElemId, steelGradeOpt, longitudinalBarNominalDiameter, longitudinalBarCrossSectionArea, barLength, role, null); } else { double meshLength; double longitudinalBarSpacing; double val = element.ArrayLength * scale; if (element.LayoutRule == RebarLayoutRule.NumberWithSpacing) { longitudinalBarSpacing = val; meshLength = val * (quantity - 1); } else { meshLength = val; longitudinalBarSpacing = val / (quantity - 1); } double meshWidth = diameter * scale; // array is in one direction only. double transverseBarNominalDiameter = longitudinalBarNominalDiameter; double transverseBarCrossSectionArea = longitudinalBarCrossSectionArea; double transverseBarSpacing = longitudinalBarSpacing; elemHnd = IFCInstanceExporter.CreateReinforcingMesh(file, rebarGUID, exporterIFC.GetOwnerHistoryHandle(), rebarName, rebarDescription, rebarObjectType, extrusionCreationData.GetLocalPlacement(), prodRep, rebarElemId, steelGradeOpt, meshLength, meshWidth, longitudinalBarNominalDiameter, transverseBarNominalDiameter, longitudinalBarCrossSectionArea, transverseBarCrossSectionArea, longitudinalBarSpacing, transverseBarSpacing); } productWrapper.AddElement(elemHnd, setter.GetLevelInfo(), extrusionCreationData, true); PropertyUtil.CreateInternalRevitPropertySets(exporterIFC, element, productWrapper); } } transaction.Commit(); } }