diff --git a/CHANGELOG.md b/CHANGELOG.md index b0944bfa..69614ada 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ API between minor releases. ### Fixed +- IFC export with Revit parameters grouped (`--ifc-revit-parameter-groups`) no longer writes several properties of one + name in a property set: each of them gets ` [parameter id]` appended. - IFC export preserves the base of a level-constrained wall whose location line already includes its base offset when its decoded body confirms the base and top. The current profile preserves separately closed sections of a straight wall across a full-height gap. - Nest fixed MEP ports under their host with `IfcRelNests` in IFC4 and write directed port links from source to sink. - Avoid overflow when triangulating trimmed faces with 46,341 or more vertices after bridging. diff --git a/docs/ifc-export.md b/docs/ifc-export.md index 1b0c6d7e..194fa187 100644 --- a/docs/ifc-export.md +++ b/docs/ifc-export.md @@ -112,7 +112,7 @@ Calling `configuration.Validate()`, `configuration.Resolve()`, or running an exp | `quantities.openingQuantityFrame` | `Supported` | `HostAxes`, `LegacyOpeningAxes` | `HostAxes` | Selects opening Width/Height axes frame. | | `propertySets.exportIfcCommonPropertySets` | `SchemaOrViewScoped` | `true` | `true` | Standard `Pset_*Common` property sets are always emitted. | | `propertySets.exportRevitPropertySets` | `Supported` | `true`, `false` | `false` | Opt-in export of Revit parameters. | -| `propertySets.groupRevitParametersByGroup` | `Supported` | `true`, `false` | `false` | Groups Revit parameter sets per group (implies `exportRevitPropertySets`). | +| `propertySets.groupRevitParametersByGroup` | `Supported` | `true`, `false` | `false` | Groups Revit parameter sets per group (implies `exportRevitPropertySets`). Property names are unique within a set: when parameters of one group share a name, each gets ` [parameter id]` appended. | | `propertySets.revitParameterUnits` | `Supported` | `internal`, `ifc` | `internal` (untyped) | Converts length, area, volume, and angle to IFC units and other physical specs to SI units when `ifc`, and assigns the project unit of each converted measure. A parameter whose spec neither the file nor the API definitions give keeps its stored number as `IfcReal`; `IfcMonetaryMeasure` has no currency unit. | | `propertySets.revitParameterNames` | `Supported` | `builtin`, `display` | `builtin` (untyped) | Uses parameter display names (with `BuiltInParameter` in `Description`) and resolves user parameter names when `display`. Property names are unique within a set: when two parameters share a name, each gets ` [parameter id]` appended (also with an explicit `builtin`). The CLI options for names and units turn the Revit property sets on, with `--ifc-config` too. | | `propertySets.exportSchedulesAsPropertySets` | `Unsupported` | `false` | `false` | Schedule Psets are not implemented; `true` fails validation. | diff --git a/src/RvtIO/Ifc/IfcExporter.cs b/src/RvtIO/Ifc/IfcExporter.cs index 6f62812f..f1c4278e 100644 --- a/src/RvtIO/Ifc/IfcExporter.cs +++ b/src/RvtIO/Ifc/IfcExporter.cs @@ -66509,10 +66509,10 @@ private void ExportPropertySets(StepWriter w, Element elem, int elemEntityId, in properties.Add((groupName, paramName, paramDescription, propValue, p.Id)); } - // IfcPropertySet requires unique property names, and distinct parameters can share one: in the - // requested naming modes every member of a clash gets its parameter id. The default naming is - // left as it was. - var clashes = RevitParameterNames == null + // IfcPropertySet requires unique property names, and distinct parameters can share one: in grouped + // sets and in the requested naming modes every member of a clash gets its parameter id. The default + // flat sets are left as they were. + var clashes = !RevitParameterGroups && RevitParameterNames == null ? null : properties.GroupBy(x => (x.Group, x.Name)).Where(g => g.Count() > 1).Select(g => g.Key).ToHashSet(); var takenNames = new HashSet<(string, string)>(); diff --git a/tests/RvtIO.Tests/IfcExporterQuantityTakeOffPropertySetTests.cs b/tests/RvtIO.Tests/IfcExporterQuantityTakeOffPropertySetTests.cs index a08c6418..b3d53f6d 100644 --- a/tests/RvtIO.Tests/IfcExporterQuantityTakeOffPropertySetTests.cs +++ b/tests/RvtIO.Tests/IfcExporterQuantityTakeOffPropertySetTests.cs @@ -161,8 +161,8 @@ public void RevitParameterGroups_WritesApiNamesInGroupPropertySets() var beam = Beam(id: 240, typeId: 241, name: "BeamType_200x300", centreX: 0); beam.Parameters.Add(new Parameter { - Id = -1012100, // PHASE_CREATED: public API name "Phase Created", group Phasing - Definition = new Definition { Name = "PHASE_CREATED" }, + Id = -1012101, // PHASE_DEMOLISHED: public API name "Phase Demolished", group Phasing + Definition = new Definition { Name = "PHASE_DEMOLISHED" }, StorageType = StorageType.Integer, Value = 7, }); @@ -185,7 +185,7 @@ public void RevitParameterGroups_WritesApiNamesInGroupPropertySets() Assert.DoesNotContain("'RevitParameters'", ifc); Assert.Single(Regex.Matches(ifc, @"IFCPROPERTYSET\('[^']*',#\d+,'Phasing'")); Assert.Single(Regex.Matches(ifc, @"IFCPROPERTYSET\('[^']*',#\d+,'Other'")); - Assert.Contains("IFCPROPERTYSINGLEVALUE('Phase Created',$,IFCINTEGER(7),$)", ifc); + Assert.Contains("IFCPROPERTYSINGLEVALUE('Phase Demolished',$,IFCINTEGER(7),$)", ifc); Assert.Contains("IFCPROPERTYSINGLEVALUE('CustomCode',$,IFCLABEL('x'),$)", ifc); } finally { Cleanup(path); } @@ -227,6 +227,60 @@ public void RevitParameterGroups_TypesValuesBySpecAndResolvesReferences() finally { Cleanup(path); } } + [Theory] + [InlineData(IfcSchema.Ifc2x3)] + [InlineData(IfcSchema.Ifc4)] + public void RevitParameterGroups_GivesEveryMemberOfANameClashItsParameterId(IfcSchema schema) + { + var beam = Beam(id: 280, typeId: 281, name: "BeamType_200x300", centreX: 0); + // distinct built-ins that the public API gives one name in one group + beam.Parameters.Add(new Parameter { Id = -1002066, StorageType = StorageType.Double, Value = 10.0 }); // Top Offset + beam.Parameters.Add(new Parameter { Id = -1001358, StorageType = StorageType.Double, Value = 20.0 }); // Top Offset + // one name in two groups lands in two sets, which is no clash + beam.Parameters.Add(new Parameter { Id = -1002062, StorageType = StorageType.String, Value = "L1" }); // Level, Constraints + beam.Parameters.Add(new Parameter { Id = -1012014, StorageType = StorageType.String, Value = "L2" }); // Level, Dimensions + // one ID twice: the ID alone does not tell them apart + beam.Parameters.Add(new Parameter { Id = -1001203, StorageType = StorageType.String, Value = "A" }); // Mark + beam.Parameters.Add(new Parameter { Id = -1001203, StorageType = StorageType.String, Value = "B" }); + var info = new RevitFileInfo(); + info.Elements.Add(beam); + string path = TempIfcPath("revit-parameter-name-clash"); + + try + { + new IfcExporter(includeRevitPropertySets: true) + { + RevitParameterGroups = true, + Profile = IfcProfile.Legacy, + Schema = schema, + }.Export(info, path); + string ifc = File.ReadAllText(path); + + AssertUniquePropertyNamesPerSet(ifc); + Assert.Contains("IFCPROPERTYSINGLEVALUE('Phase Created',", ifc); // unique: stays plain + Assert.Contains("IFCPROPERTYSINGLEVALUE('Top Offset [-1002066]',$,IFCLENGTHMEASURE(3048.),$)", ifc); + Assert.Contains("IFCPROPERTYSINGLEVALUE('Top Offset [-1001358]',$,IFCLENGTHMEASURE(6096.),$)", ifc); + Assert.Equal(2, Regex.Matches(ifc, @"IFCPROPERTYSINGLEVALUE\('Level',").Count); + Assert.Contains("IFCPROPERTYSINGLEVALUE('Mark [-1001203]',$,IFCTEXT('A'),$)", ifc); + Assert.Contains("IFCPROPERTYSINGLEVALUE('Mark [-1001203] #2',$,IFCTEXT('B'),$)", ifc); + } + finally { Cleanup(path); } + } + + private static void AssertUniquePropertyNamesPerSet(string ifc) + { + var names = Regex.Matches(ifc, @"#(\d+)=IFCPROPERTYSINGLEVALUE\('((?:[^']|'')*)'") + .ToDictionary(m => m.Groups[1].Value, m => m.Groups[2].Value); + var sets = Regex.Matches(ifc, @"IFCPROPERTYSET\('[^']*',#\d+,'([^']*)',\$,\(([^)]*)\)\)"); + Assert.NotEmpty(sets); + foreach (Match set in sets) + { + var members = set.Groups[2].Value.Split(',').Select(id => names[id.Trim().TrimStart('#')]).ToList(); + Assert.True(members.Distinct(StringComparer.Ordinal).Count() == members.Count, + $"Duplicate property names in {set.Groups[1].Value}: {string.Join(", ", members)}"); + } + } + [Fact] public void FloorTypeValidation_SetsQtoReferenceAndTheProductTypeName() {