From 4244446a8cf10576b34339621863cfafd6bb84de Mon Sep 17 00:00:00 2001 From: Axel Gehring Date: Mon, 6 Nov 2023 19:41:25 +0100 Subject: [PATCH 1/2] RVT24 Customized IFC Export for Rebar Grouping --- .../Exporter/RebarExporter.cs | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/Source/Revit.IFC.Export/Exporter/RebarExporter.cs b/Source/Revit.IFC.Export/Exporter/RebarExporter.cs index cc805b1a..2967da56 100644 --- a/Source/Revit.IFC.Export/Exporter/RebarExporter.cs +++ b/Source/Revit.IFC.Export/Exporter/RebarExporter.cs @@ -477,6 +477,8 @@ private static ISet ExportRebar(ExporterIFC exporterIFC, ElementId barLengthParamId = new ElementId(BuiltInParameter.REBAR_ELEM_LENGTH); ParameterSet rebarElementParams = rebarElement.Parameters; + int indexForNamingAndGUID = itemIndex; + HashSet bodyItems = new HashSet(); for (int ii = 0; ii < numberOfBarPositions; ii++) { if (!DoesBarExistAtPosition(rebarItem, ii)) @@ -506,8 +508,6 @@ private static ISet ExportRebar(ExporterIFC exporterIFC, } } - int indexForNamingAndGUID = ii + itemIndex; - string rebarName = NamingUtil.GetNameOverride(rebarElement, rebarNameFormated + ": " + indexForNamingAndGUID); Transform barTrf = GetBarPositionTransform(rebarItem, ii); @@ -539,7 +539,7 @@ private static ISet ExportRebar(ExporterIFC exporterIFC, Curve curve = ApplyNonConformalTransformIfPossible(baseCurve, barTrf); if (curve == null) throw new InvalidOperationException("Couldn't transform rebar curve."); - + curves.Add(curve); } } @@ -547,42 +547,44 @@ private static ISet ExportRebar(ExporterIFC exporterIFC, // For IFC4 and Structural Exchange Requirement export, Entity type not allowed for RV: IfcPolyline IFCAnyHandle compositeCurve = GeometryUtil.CreateCompositeOrIndexedCurve(exporterIFC, curves, null, null); IFCAnyHandle sweptDiskSolid = IFCInstanceExporter.CreateSweptDiskSolid(file, compositeCurve, modelDiameter / 2, null, 0, endParam); - HashSet bodyItems = new HashSet() { sweptDiskSolid }; + bodyItems.Add(sweptDiskSolid); RepresentationUtil.CreateStyledItemAndAssign(file, rebarElement.Document, materialId, sweptDiskSolid); + } IFCAnyHandle contextOfItems = ExporterCacheManager.Get3DContextHandle(IFCRepresentationIdentifier.Body); - IFCAnyHandle shapeRep = RepresentationUtil.CreateAdvancedSweptSolidRep(exporterIFC, + IFCAnyHandle shapeRep = RepresentationUtil.CreateAdvancedSweptSolidRep(exporterIFC, rebarElement, categoryId, contextOfItems, bodyItems, null); IList shapeReps = new List() { shapeRep }; prodRep = IFCInstanceExporter.CreateProductDefinitionShape(file, null, null, shapeReps); - IFCAnyHandle copyLevelPlacement = (ii == 0) ? originalPlacement : ExporterUtil.CopyLocalPlacement(file, originalPlacement); - string rebarGUID = (indexForNamingAndGUID < maxBarGUIDS) ? + //IFCAnyHandle copyLevelPlacement = (ii == 0) ? originalPlacement : ExporterUtil.CopyLocalPlacement(file, originalPlacement); + IFCAnyHandle copyLevelPlacement = originalPlacement; + + string rebarGUID = (indexForNamingAndGUID < maxBarGUIDS) ? GUIDUtil.CreateSubElementGUID(rebarElement, indexForNamingAndGUID + (int)IFCReinforcingBarSubElements.BarStart - 1) : GUIDUtil.GenerateIFCGuidFrom( GUIDUtil.CreateGUIDString(rebarElement, indexForNamingAndGUID.ToString())); - IFCAnyHandle elemHnd = IFCInstanceExporter.CreateReinforcingBar(exporterIFC, rebarElement, rebarGUID, ExporterCacheManager.OwnerHistoryHandle, - copyLevelPlacement, prodRep, steelGrade, longitudinalBarNominalDiameter, longitudinalBarCrossSectionArea, barLength, role, null); - IFCAnyHandleUtil.OverrideNameAttribute(elemHnd, rebarName); - IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcReinforcingBar); + IFCAnyHandle elemHnd = IFCInstanceExporter.CreateReinforcingBar(exporterIFC, rebarElement, rebarGUID, ExporterCacheManager.OwnerHistoryHandle, + copyLevelPlacement, prodRep, steelGrade, longitudinalBarNominalDiameter, longitudinalBarCrossSectionArea, barLength, role, null); + IFCAnyHandleUtil.OverrideNameAttribute(elemHnd, origRebarName); + IFCExportInfoPair exportInfo = new IFCExportInfoPair(IFCEntityType.IfcReinforcingBar); - // We will not add the element to the productWrapper here, but instead in the function that calls - // ExportRebar. The reason for this is that we don't currently know if the handles such be associated - // to the level or not, depending on whether they will or won't be grouped. - createdRebars.Add(new DelayedProductWrapper(rebarElement, elemHnd, setter.LevelInfo, exportInfo)); + // We will not add the element to the productWrapper here, but instead in the function that calls + // ExportRebar. The reason for this is that we don't currently know if the handles such be associated + // to the level or not, depending on whether they will or won't be grouped. + createdRebars.Add(new DelayedProductWrapper(rebarElement, elemHnd, setter.LevelInfo, exportInfo)); - CacheSubelementParameterValues(rebarElement, rebarElementParams, ii, elemHnd); + //CacheSubelementParameterValues(rebarElement, rebarElementParams, ii, elemHnd); - ExporterCacheManager.HandleToElementCache.Register(elemHnd, rebarElement.Id); - CategoryUtil.CreateMaterialAssociation(exporterIFC, elemHnd, materialId); + ExporterCacheManager.HandleToElementCache.Register(elemHnd, rebarElement.Id); + CategoryUtil.CreateMaterialAssociation(exporterIFC, elemHnd, materialId); - IFCAnyHandle typeHnd = ExporterUtil.CreateGenericTypeFromElement(rebarElement, - exportInfo, file, productWrapper); - if (!IFCAnyHandleUtil.IsNullOrHasNoValue(typeHnd)) - { - ExporterCacheManager.TypeRelationsCache.Add(typeHnd, elemHnd); - } + IFCAnyHandle typeHnd = ExporterUtil.CreateGenericTypeFromElement(rebarElement, + exportInfo, file, productWrapper); + if (!IFCAnyHandleUtil.IsNullOrHasNoValue(typeHnd)) + { + ExporterCacheManager.TypeRelationsCache.Add(typeHnd, elemHnd); } } transaction.Commit(); From 1aad41aa2955325935ad08c5cd828e9da828a291 Mon Sep 17 00:00:00 2001 From: Axel Gehring Date: Thu, 15 Aug 2024 11:38:53 +0200 Subject: [PATCH 2/2] Cand handle a IfcMaterialRebar to export specific Material Appearances. --- Source/Revit.IFC.Export/Exporter/RebarExporter.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/Revit.IFC.Export/Exporter/RebarExporter.cs b/Source/Revit.IFC.Export/Exporter/RebarExporter.cs index 4d0a016a..0ea4bba8 100644 --- a/Source/Revit.IFC.Export/Exporter/RebarExporter.cs +++ b/Source/Revit.IFC.Export/Exporter/RebarExporter.cs @@ -444,7 +444,13 @@ private static ISet ExportRebar(ExporterIFC exporterIFC, return null; ElementId materialId = ElementId.InvalidElementId; - ParameterUtil.GetElementIdValueFromElementOrSymbol(rebarElement, BuiltInParameter.MATERIAL_ID_PARAM, out materialId); + Element type = rebarElement.Document.GetElement(rebarElement.GetTypeId()); + Parameter specialRebarMaterialParameter = type.LookupParameter("IfcMaterialRebar"); + + if (specialRebarMaterialParameter != null && specialRebarMaterialParameter.HasValue && specialRebarMaterialParameter.StorageType == StorageType.ElementId && specialRebarMaterialParameter.AsElementId() != null) + materialId = specialRebarMaterialParameter.AsElementId(); + else + ParameterUtil.GetElementIdValueFromElementOrSymbol(rebarElement, BuiltInParameter.MATERIAL_ID_PARAM, out materialId); double longitudinalBarNominalDiameter = 0.0, modelDiameter = 0.0; GetBarDiameters(rebarItem, out longitudinalBarNominalDiameter, out modelDiameter);