From 97e338cdef067c5f985455d0842fcaeebbf75f60 Mon Sep 17 00:00:00 2001 From: mie <79989386+mahach666@users.noreply.github.com> Date: Wed, 2 Dec 2026 00:56:34 +0300 Subject: [PATCH 1/4] Stop a graphic style from taking names and strings that are not its own A graphic style (GStyleElem, class 2050) stores no name and no type, yet it got both from guesses, and its FamilyName followed a guessed type link. - The string walk of BlockParser accepted any bytes that read as a block header. A block repeats its size at its end; without that copy the bytes are not a block, and the text behind them went to the element whose id they happened to hold. A block is now taken only with the closing size. - The name of a style comes from the element name table of the file and from nowhere else: not from strings found in its blocks, not from strings near its id, not from a linked type. Its type name and family name are not filled through a type link either. Values copied from those names change with them: elements that took a name through a link to a style, the IFC Structural Material that pointed at a style (now the element id, not the style's name) and the fill pattern guess of a wall, which no longer accepts a style as a candidate. Tests use invented strings and synthetic blocks. Three ApiTests counts on a private fixture drop because styles no longer carry names. --- CHANGELOG.md | 9 ++ src/RvtIO/Export/ValidatedElementNames.cs | 6 +- src/RvtIO/Internal/JsonReadFacts.cs | 3 + src/RvtIO/Parsing/BlockParser.cs | 4 +- src/RvtIO/Parsing/ElementBuilder.cs | 8 +- src/RvtIO/RvtDocument.cs | 2 + tests/RvtIO.Tests/ApiTests.cs | 9 +- .../GraphicStyleForeignDataTests.cs | 146 ++++++++++++++++++ tests/RvtIO.Tests/ReaderScanTests.cs | 5 +- 9 files changed, 181 insertions(+), 11 deletions(-) create mode 100644 tests/RvtIO.Tests/GraphicStyleForeignDataTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index bd8c44f2..56c75e2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -184,6 +184,15 @@ API between minor releases. from. An element that placed that definition, or a later build from the block, could hold the same data twice, and which elements did could differ between two reads of one file. The IFC export uses this data for triangle-set bodies and for some base quantities. +- A graphic style (`GStyleElem`) no longer gets a name from bytes that only look like one, from a string stored near its + id or from a linked type, and no `FamilyName` through such a link. The class stores no name and has no type, so its + `FamilyName` is now `null`, and so is its `Name` unless the element name table of the file holds one. String built-in + parameters are no longer read from byte runs that only look like a block header, with no closing copy of the block + size. Such a run could attach the text behind it to an element that does not store it. Values that were copied from + those names change with them: an element that took its name or type name through a link to a graphic style now has its + own name or none, an IFC `Structural Material` that pointed at a graphic style is written as the element id instead of + that name, and the fill pattern guess of a wall, which accepts a named element, no longer accepts a graphic style and + takes the next candidate or none. ## [0.6.3] - 2026-11-20 diff --git a/src/RvtIO/Export/ValidatedElementNames.cs b/src/RvtIO/Export/ValidatedElementNames.cs index e5f5aad8..de92c409 100644 --- a/src/RvtIO/Export/ValidatedElementNames.cs +++ b/src/RvtIO/Export/ValidatedElementNames.cs @@ -77,7 +77,8 @@ internal static int Apply(RevitFileInfo info, JsonReadFacts state, /// The validated names of the element in priority order. A named element (a type, level or material) reports /// its own name and nothing else; only an occurrence with no name of its own reports the name of its type, as the /// Revit API does. A type element (it owns a Symbol-subclass root, ) has no - /// type: the link it carries points at another symbol, so without a validated name of its own it has none. + /// type: the link it carries points at another symbol, so without a validated name of its own it has none. A graphic + /// style has no type either. /// Two different names in the result would contradict each other. internal static IEnumerable Candidates( Element element, IReadOnlyDictionary byId, IReadOnlyDictionary counts, JsonReadFacts state) @@ -89,7 +90,8 @@ internal static IEnumerable Candidates( named = true; yield return validation; } - if (named || element.Id == 0 || state.SystemTypeRoots.ContainsKey((uint)element.Id)) yield break; + if (named || element.Id == 0 || state.SystemTypeRoots.ContainsKey((uint)element.Id) + || state.IsGraphicStyle((uint)element.Id)) yield break; foreach (Validation validation in TypeNames(element, byId, counts, state)) yield return validation; } diff --git a/src/RvtIO/Internal/JsonReadFacts.cs b/src/RvtIO/Internal/JsonReadFacts.cs index 7ff1d38e..28506ff9 100644 --- a/src/RvtIO/Internal/JsonReadFacts.cs +++ b/src/RvtIO/Internal/JsonReadFacts.cs @@ -7,6 +7,9 @@ internal class JsonReadFacts { /// First block class ID (low 16 bits) seen per element in the continuous walk. public Dictionary ElemClassIdx { get; } = new(); + /// The element is a GStyleElem (class 2050). Its schema chain stores no name and no type, so a name found in its + /// blocks, near its id or behind a type link belongs to something else. + internal bool IsGraphicStyle(uint eid) => ElemClassIdx.GetValueOrDefault(eid) == 2050; /// The file's own schema, or null for the shipped 2022 layout. public FileSchema? WideSchema { get; set; } /// The element's own name from its root in the file's schema. diff --git a/src/RvtIO/Parsing/BlockParser.cs b/src/RvtIO/Parsing/BlockParser.cs index f93d10b7..02bc23c0 100644 --- a/src/RvtIO/Parsing/BlockParser.cs +++ b/src/RvtIO/Parsing/BlockParser.cs @@ -2428,7 +2428,9 @@ internal static void CollectBipStrings(byte[] d, ParsingState state) if (dataSize == 0) { pos++; continue; } if (pos + 16 + (int)dataSize > d.Length) break; - if (ElementIdEncoding.IsSupported(eid)) + // A block repeats its size at its end. Without that copy the bytes only read as a header, and the strings behind + // them are not those of the id they happen to hold. + if (ElementIdEncoding.IsSupported(eid) && BitConverter.ToUInt32(d, pos + 12 + (int)dataSize) == dataSize) { int ds = pos + 16, de = ds + (int)dataSize; int limit = de - 9; diff --git a/src/RvtIO/Parsing/ElementBuilder.cs b/src/RvtIO/Parsing/ElementBuilder.cs index 847c85e9..795b6bdb 100644 --- a/src/RvtIO/Parsing/ElementBuilder.cs +++ b/src/RvtIO/Parsing/ElementBuilder.cs @@ -1383,6 +1383,8 @@ private static bool TryResolveFamilyNameViaTable( { if (state.ElementNameTable.TryGetValue(eid, out var tableName)) return tableName; + // the class stores no name, so only the name table can have one for it + if (state.IsGraphicStyle(eid)) return null; if (state.NativeElementNames.TryGetValue(eid, out var nativeName)) return nativeName; if (state.WideNames.TryGetValue(eid, out var wideName) && !string.IsNullOrWhiteSpace(wideName)) @@ -5850,7 +5852,7 @@ internal static void ApplyValidatedFamilyNamesFromCanonicalTypeId( { foreach (Element element in elements) { - if (element.TypeId <= 0) continue; + if (element.TypeId <= 0 || state.IsGraphicStyle((uint)element.Id)) continue; if (TryResolveFamilyNameViaTable((uint)element.TypeId, state, out var famName) && !string.IsNullOrWhiteSpace(famName)) element.FamilyName = famName; @@ -6302,6 +6304,7 @@ public static IReadOnlyDictionary PostProcess(RevitFileInfo rvtInf // Materials are document definitions, not family instances. Their TypeId is an internal // material/asset link and must not replace the authored name. if (e.CategoryId is -2000700 or -2000220) continue; + if (state?.IsGraphicStyle((uint)e.Id) == true) continue; // it has no type if (e.TypeId > 0 && idToName.TryGetValue(e.TypeId, out var typeName)) { // Instances always use type name; only keep existing name if no type available @@ -6379,6 +6382,7 @@ public static IReadOnlyDictionary PostProcess(RevitFileInfo rvtInf int realHasTypeParam = 0, realNoNameEntryHasTypeParam = 0; foreach (var e in rvtInfo.Elements) { + if (state.IsGraphicStyle((uint)e.Id)) continue; // no type, so no family bool isReal = !e.IsDiscovered && !e.IsBlockOnly; if (isReal) realTotal++; // Symbol id: the element's own id if IT has a name entry with a parent, otherwise its @@ -6542,7 +6546,7 @@ void ReportDistinctMissing(string label, Dictionary counts) // reports its TYPE's name. Apply where the type name is table-backed. foreach (var e in rvtInfo.Elements) { - if (e.CategoryId == -2000220) continue; + if (e.CategoryId == -2000220 || state.IsGraphicStyle((uint)e.Id)) continue; if (state.ElementNameTable.ContainsKey((uint)e.Id)) continue; // has own name var tp = e.Parameters.FirstOrDefault(p => p.Id == -1002050); if (tp?.Value is int tid && tid > 0 && tid != e.Id diff --git a/src/RvtIO/RvtDocument.cs b/src/RvtIO/RvtDocument.cs index 95b66193..aaf9d600 100644 --- a/src/RvtIO/RvtDocument.cs +++ b/src/RvtIO/RvtDocument.cs @@ -223,6 +223,8 @@ private void ResolveElementNames() // level whose ELEM_TYPE_PARAM resolves to a wall type was renamed to that type, e.g. "8mm Head"). if (elem.Category is "OST_Levels" or "OST_Views" or "OST_Grids" or "OST_Rooms" or "OST_Sheets" or "OST_Areas" or "OST_TextNotes") continue; + // A graphic style (GStyleElem, class 2050) has no type: a type link on it is a guess. + if (elem.NativeRecordClass == 2050) continue; int typeId = elem.FamilyTypeId; if (typeId <= 0) continue; if (!_elemById.TryGetValue(typeId, out var typeElem)) continue; diff --git a/tests/RvtIO.Tests/ApiTests.cs b/tests/RvtIO.Tests/ApiTests.cs index 83633fc3..f95a40fd 100644 --- a/tests/RvtIO.Tests/ApiTests.cs +++ b/tests/RvtIO.Tests/ApiTests.cs @@ -1025,7 +1025,7 @@ public void InvestigateNameStoragePattern() foreach (int id in new[] { 263584, 263597, 263610, 263623, 263733, 263865 }) Assert.Equal(1757, _doc.GetElement(id)!.TypeId); Assert.Equal(100907, _doc.GetElement(290112)!.TypeId); - Assert.Equal(16, _doc.Elements.Count(e => e.Name != null && e.Name.Contains("Фундамент"))); + Assert.Equal(12, _doc.Elements.Count(e => e.Name != null && e.Name.Contains("Фундамент"))); Assert.Equal([6844], Enumerable.Range(6840, 11).Where(id => _doc.GetElement(id) != null)); var e6844 = _doc.GetElement(6844); @@ -1094,9 +1094,10 @@ public void InvestigateNameStoragePattern() [SkippableFact] public void SearchBetonString() { - // both counts include id 172544, a load case by its header that Revit does not return as an element - Assert.Equal(46, _doc.Elements.Count(e => e.Name != null && e.Name.Contains("Бетон"))); - Assert.Equal(55,_doc.Elements.Count(e => e.Name != null && e.Name.Contains("300"))); + // both counts include id 172544, a load case by its header that Revit does not return as an element; a graphic + // style has no name of its own here and is in neither + Assert.Equal(42, _doc.Elements.Count(e => e.Name != null && e.Name.Contains("Бетон"))); + Assert.Equal(49,_doc.Elements.Count(e => e.Name != null && e.Name.Contains("300"))); var material = _doc.GetElement(100935)!; Assert.Equal("OST_Materials", material.Category); Assert.Equal("Бетон", material.Name); diff --git a/tests/RvtIO.Tests/GraphicStyleForeignDataTests.cs b/tests/RvtIO.Tests/GraphicStyleForeignDataTests.cs new file mode 100644 index 00000000..5006ae21 --- /dev/null +++ b/tests/RvtIO.Tests/GraphicStyleForeignDataTests.cs @@ -0,0 +1,146 @@ +using System.Text; +using RvtIO.Export; +using RvtIO.Internal; +using RvtIO.Model; +using RvtIO.Parsing; +using Xunit; + +namespace RvtIO.Tests; + +/// Names and string built-in parameters an element must not take from bytes that are not its own. +public class GraphicStyleForeignDataTests +{ + private const int Bip = -1002500; + private const ushort GraphicStyleClass = 2050; + + [Fact] + public void CollectBipStrings_TakesNothingFromARunThatNoCopyOfItsSizeCloses() + { + // Two byte runs that read as block headers stand in front of the record of element 123: one names an element + // without a record of its own, one names element 123, whose first value of a parameter is the one that stays. + byte[] chunk = + [ + .. Run(456, KeyedString(Bip, "Foreign")), + .. Run(123, KeyedString(Bip, "Foreign")), + .. Item(123, KeyedString(Bip, "Own")), + ]; + var state = new ParsingState(); + + BlockParser.CollectBipStrings(chunk, state); + + Assert.False(state.BipKeyedStrings.ContainsKey(456)); + Assert.Equal("Own", state.BipKeyedStrings[123][Bip]); + } + + [Fact] + public void ResolveElementName_OfAGraphicStyle_TakesNoNameFromItsStringsOrFromNearbyOnes() + { + var state = new ParsingState(); + foreach (uint id in new uint[] { 30, 31 }) + { + state.ElemStrings[id] = ["In its block"]; + state.ElemScanStrings[id] = ["Nearby"]; + } + state.ElemScanStrings[32] = ["Nearby"]; + state.ElemScanStrings[33] = ["Nearby"]; + state.ElemClassIdx[30] = GraphicStyleClass; + state.ElemClassIdx[32] = GraphicStyleClass; + state.ElemClassIdx[33] = GraphicStyleClass; + state.ElementNameTable[33] = "Stored"; + // despite its name the map holds what a look through a block's bytes took for a name + state.ElemClassIdx[34] = GraphicStyleClass; + state.NativeElementNames[34] = "From bytes"; + state.NativeElementNames[35] = "From bytes too"; + + Assert.Null(ElementBuilder.ResolveElementName(30, state)); + Assert.Equal("In its block", ElementBuilder.ResolveElementName(31, state)); + Assert.Null(ElementBuilder.ResolveElementName(32, state)); + Assert.Equal("Stored", ElementBuilder.ResolveElementName(33, state)); + Assert.Null(ElementBuilder.ResolveElementName(34, state)); + Assert.Equal("From bytes too", ElementBuilder.ResolveElementName(35, state)); + } + + [Fact] + public void ValidatedName_OfAGraphicStyle_IsNeverThatOfALinkedType() + { + var type = new Element { Id = 11, ValidatedIfcTypeOwnName = "Type name" }; + var style = new Element { Id = 30, TypeId = 11, Parameters = [TypeParameter(11)] }; + var instance = new Element { Id = 40, TypeId = 11, Parameters = [TypeParameter(11)] }; + var byId = new[] { type, style, instance }.ToDictionary(element => element.Id); + var counts = byId.Keys.ToDictionary(id => id, _ => 1); + var state = new ParsingState(); + state.ElemClassIdx[30] = GraphicStyleClass; + + Assert.Null(ValidatedElementNames.Resolve(style, byId, counts, state)); + Assert.Equal("Type name", ValidatedElementNames.Resolve(instance, byId, counts, state)?.Name); + } + + [Fact] + public void PostProcess_GivesAGraphicStyleNoTypeNameAndNoFamilyName() + { + var type = new Element { Id = 11, TypeId = -1, Name = "Type name" }; + var byTypeId = new Element { Id = 30, TypeId = 11 }; + var byTypeParameter = new Element { Id = 31, TypeId = -1, Parameters = [TypeParameter(11)] }; + var instance = new Element { Id = 40, TypeId = 11 }; + var info = new RevitFileInfo(); + info.Elements.AddRange([type, byTypeId, byTypeParameter, instance]); + var state = new ParsingState(); + state.ElemClassIdx[30] = GraphicStyleClass; + state.ElemClassIdx[31] = GraphicStyleClass; + state.ElementNameTable[11] = "Type name"; + // the name entry of the type leads to that of its family + state.NameEntryParentHolder[11] = 1; + state.NameHolderTarget[1] = 2; + state.ElementNameTable[2] = "Family"; + + ElementBuilder.PostProcess(info, state); + + Assert.Null(byTypeId.Name); + Assert.Null(byTypeParameter.Name); + Assert.Equal("Type name", instance.Name); + Assert.Null(byTypeId.FamilyName); + Assert.Null(byTypeParameter.FamilyName); + Assert.Equal("Family", instance.FamilyName); + } + + [Fact] + public void Document_GivesAGraphicStyleNoTypeNameAndNoFamilyName() + { + var type = new Element { Id = 11, TypeId = -1, Name = "Type name", FamilyName = "Family" }; + var style = new Element { Id = 30, NativeRecordClass = GraphicStyleClass, Parameters = [TypeParameter(11)] }; + var instance = new Element { Id = 40, Parameters = [TypeParameter(11)] }; + var info = new RevitFileInfo(); + info.Elements.AddRange([type, style, instance]); + + // the document works on copies of the elements + var copies = RvtDocument.FromInfo(info).Elements.ToDictionary(element => element.Id); + + Assert.Null(copies[30].Name); + Assert.Null(copies[30].FamilyName); + Assert.Equal("Type name", copies[40].Name); + Assert.Equal("Family", copies[40].FamilyName); + } + + private static Parameter TypeParameter(int typeId) => + BipHelpers.MakeBipParam(-1002050, "ELEM_TYPE_PARAM", StorageType.ElementId, typeId); + + // [built-in parameter id][length in characters][UTF-16] + private static byte[] KeyedString(int bip, string text) => + [.. BitConverter.GetBytes(bip), .. BitConverter.GetBytes(text.Length), .. Encoding.Unicode.GetBytes(text)]; + + // [owner][checksum][size][class, two bytes of padding, data][size] + private static byte[] Item(uint owner, byte[] data) + { + byte[] body = [.. BitConverter.GetBytes((ushort)3708), 0, 0, .. data]; + return [.. BitConverter.GetBytes(owner), 0, 0, 0, 0, .. BitConverter.GetBytes(body.Length), .. body, + .. BitConverter.GetBytes(body.Length)]; + } + + // looks like a header to a walk by sizes: the size leads to the next byte after the run, but no copy of it closes it + private static byte[] Run(uint owner, byte[] data) + { + int size = 4 + data.Length + 4; + return [.. BitConverter.GetBytes(owner), 0, 0, 0, 0, .. BitConverter.GetBytes(size), 0, 0, 0, 0, .. data, + .. new byte[size - data.Length]]; + } +} diff --git a/tests/RvtIO.Tests/ReaderScanTests.cs b/tests/RvtIO.Tests/ReaderScanTests.cs index f3077e13..6c770347 100644 --- a/tests/RvtIO.Tests/ReaderScanTests.cs +++ b/tests/RvtIO.Tests/ReaderScanTests.cs @@ -47,9 +47,10 @@ void WriteEntry(int start, uint holder, uint element, string name, bool masked) [Fact] public void KeyedStringsKeepUnalignedBoundaryIdsAndTheLastPossibleEntry() { - byte[] chunk = new byte[16 + 31]; + byte[] chunk = new byte[16 + 35]; BinaryPrimitives.WriteUInt32LittleEndian(chunk, 42); - BinaryPrimitives.WriteUInt32LittleEndian(chunk.AsSpan(8), 31); + BinaryPrimitives.WriteUInt32LittleEndian(chunk.AsSpan(8), 35); + BinaryPrimitives.WriteUInt32LittleEndian(chunk.AsSpan(12 + 35), 35); // the copy of the size that closes the block WriteString(17, -1_200_000, 'A'); WriteString(27, -1_200_001, 'B'); WriteString(37, -1_000_000, 'C'); From a516c2a1e3d64c67591f0bf0b89166f0a36ed9fc Mon Sep 17 00:00:00 2001 From: mie <79989386+mahach666@users.noreply.github.com> Date: Wed, 2 Dec 2026 15:57:11 +0300 Subject: [PATCH 2/4] Give a graphic style and a category element no type from a guess A graphic style (GStyleElem, class 2050) and a category element (CategoryElem, class 632) store no type, yet the reader gave them one from their references, and took the name, the family and the values behind it from something that is no type. - A category element takes its name from the name its category stores (CategoryNames), not from a string near its id or from a linked type. - A guess of the type of an element that names a graphic style or a category element makes no type: the type id from references, the voted type parameters, the dim style of a weak dimension and the type that RvtDocument takes for an element that has none. Such an element has no type id and none of ELEM_TYPE_PARAM, SYMBOL_ID_PARAM and ELEM_FAMILY_AND_TYPE_PARAM unless the file stores one; a family the file stores (ELEM_FAMILY_PARAM) stays. - The two kinds of element no longer own a guessed type, so what they took through it goes: CLEAR_COVER_*, FAMILY_LEVEL_PARAM, STRUCTURAL_MATERIAL_PARAM, the fill pattern and the parameters of the elements of that type. They are no longer counted as types by TypeElementIds and WhereElementIsElementType when only a guess named them. - STRUCTURAL_MATERIAL_PARAM comes only from a MaterialElem, and the fill pattern guess of a wall only from a FillPatternElem. - A MaterialElem keeps the name the reader gave it. RvtDocument replaced it with the name of the element its ELEM_TYPE_PARAM names, which is a guess for a material, unless a graphic style happened to name the material as its type. The exemption is by class, not by the category of materials, which other elements inherit through their references. On the 53 private samples every difference of the element dumps before and after is explained by one of these rules; elements that only such a guess supported as evidence (votes, known types) may get another type or none. Two ApiTests on a private fixture expected the old material names and counts and now expect the names the file stores. Tests use synthetic documents. --- CHANGELOG.md | 35 ++ src/RvtIO/Export/ValidatedElementNames.cs | 4 +- src/RvtIO/Internal/JsonReadFacts.cs | 5 + src/RvtIO/Model/Element.cs | 8 + src/RvtIO/Parsing/ElementBuilder.cs | 77 +++- src/RvtIO/RvtDocument.cs | 29 +- tests/RvtIO.Tests/ApiTests.cs | 16 +- tests/RvtIO.Tests/CategoryElementNameTests.cs | 131 ++++++ tests/RvtIO.Tests/NoTypeDocumentGuessTests.cs | 171 +++++++ tests/RvtIO.Tests/NoTypeElementLinkTests.cs | 428 ++++++++++++++++++ .../WallThermalFallbackProvenanceTests.cs | 24 +- 11 files changed, 895 insertions(+), 33 deletions(-) create mode 100644 tests/RvtIO.Tests/CategoryElementNameTests.cs create mode 100644 tests/RvtIO.Tests/NoTypeDocumentGuessTests.cs create mode 100644 tests/RvtIO.Tests/NoTypeElementLinkTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 56c75e2d..20061245 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -193,6 +193,41 @@ API between minor releases. own name or none, an IFC `Structural Material` that pointed at a graphic style is written as the element id instead of that name, and the fill pattern guess of a wall, which accepts a named element, no longer accepts a graphic style and takes the next candidate or none. +- A category element (`CategoryElem`) takes its `Name` from the name its category stores, and has none when the file + stores an empty name, a repeated block or no name that could be read, unless the element name table, a name the file + stores for the element itself or the schema walk of the file holds one. Before, a string found in its blocks or near + its id, which is nearly always the name of a neighbouring element, or the name of a type it was linked to, became its + name. Like a graphic style it has no type, so it takes no type name and no `FamilyName` through a link. +- A guess of the type of an element that names a graphic style or a category element makes no type. Neither stores a + type, so an element that took one as its type took the name, the family and the values behind it from something that is + no type. This covers the type id taken from the references or from a type parameter, the type parameters + (`ELEM_TYPE_PARAM`, `SYMBOL_ID_PARAM`, `ELEM_FAMILY_AND_TYPE_PARAM`) voted from the references of an element, the dim + style of a weak dimension and the type that `RvtDocument` takes from the references of an element that has none. Such + an element now has no type id and no such type parameter instead (its `TypeId` is -1), and + `FilteredElementCollector.WhereElementIsElementType` and `TypeElementIds` no longer count a graphic style or a category + element that only a guess named as a type. The other guesses are unchanged, and where the guess was of another category + than the element, the type parameters follow the type id of the element. What the file stores in the block of an + element stays as it was read. +- The structural material (`STRUCTURAL_MATERIAL_PARAM`, the IFC `Structural Material`) is taken only from a material + element (`MaterialElem`) instead of any element that carries the category of materials, which an element also gets from + the elements it refers to. An IFC `Structural Material` that named a graphic style, a category element or another + element that is no material now names the material or is left out, and the values derived from the material (thermal and + analytical properties) change with it. The fill pattern guess of a wall accepts only a fill pattern element + (`FillPatternElem`) instead of any named element in the id range, so it no longer names a dimension style or a + parameter element. +- A graphic style (`GStyleElem`) and a category element (`CategoryElem`) get no type from a guess. The file stores no + type for either, and the references they hold were taken for one: the lowest-id element of the same category among + them, or the voted one. They now have `TypeId` -1 and none of `ELEM_TYPE_PARAM`, `SYMBOL_ID_PARAM` and + `ELEM_FAMILY_AND_TYPE_PARAM` unless the file stores one; `ELEM_FAMILY_PARAM`, where the file stores a family, stays. + What they took through that type goes with it: `CLEAR_COVER_*`, `FAMILY_LEVEL_PARAM`, `STRUCTURAL_MATERIAL_PARAM`, the + fill pattern, and the user and shared parameters of the elements of that type, which they were given as if they were + one of them. An element that only such a guess named as its type is no longer in `TypeElementIds` or + `FilteredElementCollector.WhereElementIsElementType`. An element whose own type guess took such a known type as + evidence may now get another type or none, since the evidence was no type. +- A material (`MaterialElem`) keeps the name the reader gave it. `RvtDocument` replaced it with the name of the element + its `ELEM_TYPE_PARAM` names, which for a material is a guess, unless a graphic style happened to name the material as + its type. The name pass of the reader already left materials alone; an element that only carries the category of + materials, which it gets from what it refers to, is still named by its type. ## [0.6.3] - 2026-11-20 diff --git a/src/RvtIO/Export/ValidatedElementNames.cs b/src/RvtIO/Export/ValidatedElementNames.cs index de92c409..294c69f6 100644 --- a/src/RvtIO/Export/ValidatedElementNames.cs +++ b/src/RvtIO/Export/ValidatedElementNames.cs @@ -78,7 +78,7 @@ internal static int Apply(RevitFileInfo info, JsonReadFacts state, /// its own name and nothing else; only an occurrence with no name of its own reports the name of its type, as the /// Revit API does. A type element (it owns a Symbol-subclass root, ) has no /// type: the link it carries points at another symbol, so without a validated name of its own it has none. A graphic - /// style has no type either. + /// style and a category element have no type either. /// Two different names in the result would contradict each other. internal static IEnumerable Candidates( Element element, IReadOnlyDictionary byId, IReadOnlyDictionary counts, JsonReadFacts state) @@ -91,7 +91,7 @@ internal static IEnumerable Candidates( yield return validation; } if (named || element.Id == 0 || state.SystemTypeRoots.ContainsKey((uint)element.Id) - || state.IsGraphicStyle((uint)element.Id)) yield break; + || state.StoresNoType((uint)element.Id)) yield break; foreach (Validation validation in TypeNames(element, byId, counts, state)) yield return validation; } diff --git a/src/RvtIO/Internal/JsonReadFacts.cs b/src/RvtIO/Internal/JsonReadFacts.cs index 28506ff9..22eb4f7e 100644 --- a/src/RvtIO/Internal/JsonReadFacts.cs +++ b/src/RvtIO/Internal/JsonReadFacts.cs @@ -10,6 +10,11 @@ internal class JsonReadFacts /// The element is a GStyleElem (class 2050). Its schema chain stores no name and no type, so a name found in its /// blocks, near its id or behind a type link belongs to something else. internal bool IsGraphicStyle(uint eid) => ElemClassIdx.GetValueOrDefault(eid) == 2050; + /// The element is a GStyleElem or a CategoryElem (class 632). Neither stores a type, so a type link on it is a + /// guess and a name or family behind it is not its own. + internal bool StoresNoType(uint eid) => IsGraphicStyle(eid) || IsCategoryElement(eid); + /// The element is a CategoryElem (class 632). Its name is the one its Category stores. + internal bool IsCategoryElement(uint eid) => ElemClassIdx.GetValueOrDefault(eid) == 632; /// The file's own schema, or null for the shipped 2022 layout. public FileSchema? WideSchema { get; set; } /// The element's own name from its root in the file's schema. diff --git a/src/RvtIO/Model/Element.cs b/src/RvtIO/Model/Element.cs index 90e65f83..cfcaba7c 100644 --- a/src/RvtIO/Model/Element.cs +++ b/src/RvtIO/Model/Element.cs @@ -1065,6 +1065,14 @@ internal string? ValidatedStairComponentTypeName /// (), so type guesses must not replace it. internal bool TypeFromNativePointer { get; set; } + /// The id of the graphic style or the category element that a guess of this element's type named (0: none did). + /// Neither is a type: the element has none through that guess, and no other guess puts a type in its place. + internal int TypeGuessOnNoType { get; set; } + + /// The id of the graphic style or the category element that the guess of named (0: none did), + /// which leaves the element without a type id. + internal int TypeIdOnNoType { get; set; } + /// Closed-shell quantities of the solids at the Coarse, Medium and Fine detail levels (index 0, 1, 2); null at a level whose /// solids are not all closed shells of plane faces. See ElementBuilder.ApplyInstanceQuantities. [JsonIgnore] diff --git a/src/RvtIO/Parsing/ElementBuilder.cs b/src/RvtIO/Parsing/ElementBuilder.cs index 795b6bdb..ce52ce15 100644 --- a/src/RvtIO/Parsing/ElementBuilder.cs +++ b/src/RvtIO/Parsing/ElementBuilder.cs @@ -1385,10 +1385,15 @@ private static bool TryResolveFamilyNameViaTable( return tableName; // the class stores no name, so only the name table can have one for it if (state.IsGraphicStyle(eid)) return null; + // a category element has the name its Category stores + if (state.CategoryNames.TryGetValue(eid, out var category) && category is { BlockCount: 1, Name: not null }) + return category.Name.Length > 0 ? category.Name : null; if (state.NativeElementNames.TryGetValue(eid, out var nativeName)) return nativeName; if (state.WideNames.TryGetValue(eid, out var wideName) && !string.IsNullOrWhiteSpace(wideName)) return wideName; + // what is left is a string found near the id of a category element: that of another element + if (state.IsCategoryElement(eid)) return null; string? foundName = null; if (state.ElemStrings.TryGetValue(eid, out var blkStrs)) foundName = blkStrs.FirstOrDefault(StringScanner.IsValidElementName); @@ -1577,8 +1582,21 @@ private static int TypeParamOf(Element e) /// Resolve ELEM_TYPE_PARAM / ELEM_FAMILY_AND_TYPE_PARAM / SYMBOL_ID_PARAM to the real type /// element id for instances whose binary body didn't carry it. /// - internal static void ResolveTypeParams(RevitFileInfo info, IReadOnlyDictionary byId) + internal static void ResolveTypeParams(RevitFileInfo info, IReadOnlyDictionary byId, ParsingState? state = null) { + // A graphic style and a category element are no type: a guess that lands on one makes none. The type parameters then follow + // the type id of the element where that names a type of its category and the guess is of another one, as the later fix of + // the type parameters (EnrichTypeLevelBips) makes them follow it; otherwise the element has none. + bool NoType(int id) => state?.StoresNoType((uint)id) == true; + int TypeOfGuess(Element e, int guess) + { + if (!NoType(guess)) return guess; + if (e.TypeId > 0 && byId.TryGetValue(e.TypeId, out var typeOfId) && typeOfId.CategoryId == e.CategoryId + && byId.TryGetValue(guess, out var landedOn) && landedOn.CategoryId != e.CategoryId) return e.TypeId; + e.TypeGuessOnNoType = guess; + return -1; + } + // Weak (automatic) dimensions reference their dim style FIRST - a small built-in element id // (e.g. 277), below the >1000 cutoff of the voting heuristic underneath. foreach (var e in info.Elements) @@ -1586,6 +1604,8 @@ internal static void ResolveTypeParams(RevitFileInfo info, IReadOnlyDictionary 0 }) continue; int t = e.References[0]; if (t <= 0 || TypeParamOf(e) > 0) continue; + t = TypeOfGuess(e, t); + if (t <= 0) continue; AddBipIfMissing(e, -1002050, "ELEM_TYPE_PARAM", t); AddBipIfMissing(e, -1002052, "ELEM_FAMILY_AND_TYPE_PARAM", t); AddBipIfMissing(e, -1002000, "SYMBOL_ID_PARAM", t); @@ -1604,8 +1624,9 @@ internal static void ResolveTypeParams(RevitFileInfo info, IReadOnlyDictionary 0) seed.Add(t); + if (e.TypeGuessOnNoType > 1000) seed.Add(e.TypeGuessOnNoType); if (e.References is not { Count: > 0 }) continue; - if (t <= 0) unresolved.Add(e); + if (t <= 0 && e.TypeGuessOnNoType == 0 && !NoType(e.Id)) unresolved.Add(e); // a style or a category element has no type if (e.CategoryId is not int c) continue; seenRefs.Clear(); foreach (var r in e.References) @@ -1652,6 +1673,8 @@ internal static void ResolveTypeParams(RevitFileInfo info, IReadOnlyDictionary PostProcess(RevitFileInfo rvtInf .ToDictionary(pair => (int)pair.Key, pair => pair.Value.Name!); var elemByIdLookup = rvtInfo.Elements.ToDictionary(e => e.Id); + // A graphic style and a category element are no type: a guess that lands on one makes none. + bool NoType(int id) => state?.StoresNoType((uint)id) == true; // Inherit category from type element or references Phase 1: TypeId and ELEM_TYPE_PARAM // (safe, direct type->instance) @@ -6245,6 +6270,9 @@ public static IReadOnlyDictionary PostProcess(RevitFileInfo rvtInf ReadOnlySpan typeParamIds = [-1002050, -1002000, -1002052]; foreach (var e in rvtInfo.Elements) { + // The file stores no type for a graphic style or a category element: what its references would give is a guess about + // something that has no type. + if (NoType(e.Id)) continue; // Trust current TypeId only if it resolves to an element of the SAME category. // Otherwise it's likely a Tf-class index or a leaked phase/sentinel value. bool currentValid = e.TypeId > 0 && elemByIdLookup.TryGetValue(e.TypeId, out var curType) @@ -6275,7 +6303,16 @@ public static IReadOnlyDictionary PostProcess(RevitFileInfo rvtInf } } } - if (resolved.HasValue) e.TypeId = resolved.Value; + if (!resolved.HasValue) continue; + if (!NoType(resolved.Value)) { e.TypeId = resolved.Value; continue; } + // A graphic style or a category element is no type: the element keeps no type id. The parameters that hold no element + // would have taken it as their value below, which makes it a known type to the vote of the type parameters. + e.TypeIdOnNoType = resolved.Value; + foreach (int paramId in typeParamIds) + { + var p = FindParameterById(e.Parameters, paramId); + if (p != null && !(p.Value is int v && v > 0 && elemByIdLookup.ContainsKey(v))) e.TypeGuessOnNoType = resolved.Value; + } } // Also overwrite ELEM_TYPE_PARAM / SYMBOL_ID_PARAM / ELEM_FAMILY_AND_TYPE_PARAM values when // the resolved TypeId differs from the stored garbage (e.g. 528 Tf-class index) @@ -6304,7 +6341,7 @@ public static IReadOnlyDictionary PostProcess(RevitFileInfo rvtInf // Materials are document definitions, not family instances. Their TypeId is an internal // material/asset link and must not replace the authored name. if (e.CategoryId is -2000700 or -2000220) continue; - if (state?.IsGraphicStyle((uint)e.Id) == true) continue; // it has no type + if (state?.StoresNoType((uint)e.Id) == true) continue; // it has no type if (e.TypeId > 0 && idToName.TryGetValue(e.TypeId, out var typeName)) { // Instances always use type name; only keep existing name if no type available @@ -6382,7 +6419,7 @@ public static IReadOnlyDictionary PostProcess(RevitFileInfo rvtInf int realHasTypeParam = 0, realNoNameEntryHasTypeParam = 0; foreach (var e in rvtInfo.Elements) { - if (state.IsGraphicStyle((uint)e.Id)) continue; // no type, so no family + if (state.StoresNoType((uint)e.Id)) continue; // no type, so no family bool isReal = !e.IsDiscovered && !e.IsBlockOnly; if (isReal) realTotal++; // Symbol id: the element's own id if IT has a name entry with a parent, otherwise its @@ -6546,7 +6583,7 @@ void ReportDistinctMissing(string label, Dictionary counts) // reports its TYPE's name. Apply where the type name is table-backed. foreach (var e in rvtInfo.Elements) { - if (e.CategoryId == -2000220 || state.IsGraphicStyle((uint)e.Id)) continue; + if (e.CategoryId == -2000220 || state.StoresNoType((uint)e.Id)) continue; if (state.ElementNameTable.ContainsKey((uint)e.Id)) continue; // has own name var tp = e.Parameters.FirstOrDefault(p => p.Id == -1002050); if (tp?.Value is int tid && tid > 0 && tid != e.Id @@ -6707,7 +6744,7 @@ void ReportDistinctMissing(string label, Dictionary counts) } } - ResolveTypeParams(rvtInfo, elemByIdLookup); + ResolveTypeParams(rvtInfo, elemByIdLookup, state); ApplyDetailLines(rvtInfo, state); ApplyBlockSignatureCategories(rvtInfo, state); // Native (schema-deserialized) params land BEFORE the default-emitting passes so @@ -8205,7 +8242,10 @@ void Accumulate(ref RefScan scan, int rid, int ownerId, bool isWall) if (rid == ownerId || rid <= 0) return; switch (category) { - case -2000700: scan.MaterialId ??= rid; break; // OST_Materials + case -2000700: // OST_Materials: an element has this category by inheritance from what it refers to, but is a material + // only when the file stores it as one (MaterialElem, class 2486) + if (state.ElemClassIdx.GetValueOrDefault((uint)rid) == 2486) scan.MaterialId ??= rid; + break; case -2009014: scan.CoverTypeId ??= rid; break; // OST_CoverType case -2000081: scan.FillPatternId ??= rid; break; // OST_FillPatterns case -2000240: // OST_Levels - first is base, second is top @@ -8217,9 +8257,11 @@ void Accumulate(ref RefScan scan, int rid, int ownerId, bool isWall) if (scan.CoverTypeId == null && refElem.Category == "OST_CoverType") scan.CoverTypeId = rid; if (scan.FillPatternId == null && refElem.Category == "OST_FillPatterns") scan.FillPatternId = rid; // Fill pattern often has no category in our output but its name is the pattern name - // (for example concrete or hatch names) - accept refs in the right ID range as candidates. + // (for example concrete or hatch names) - accept refs in the right ID range as candidates, + // when the file stores them as fill pattern elements (class 1851). if (scan.FillPatternId == null && refElem.Category == null && rid > 100 && rid < 10000 - && !string.IsNullOrEmpty(refElem.Name) && isWall) + && !string.IsNullOrEmpty(refElem.Name) && isWall + && state.ElemClassIdx.GetValueOrDefault((uint)rid) == 1851) scan.FillPatternId = rid; } RefScan ScanRefs(Element e, List? typeRefs, bool isWall) @@ -8305,6 +8347,19 @@ void EnsureBipOrFixNull(int id, string name, StorageType st, int value, p.Value = e.TypeId; } } + else if (e.TypeIdOnNoType > 0 && elemById.TryGetValue(e.TypeIdOnNoType, out var noType) && noType.CategoryId == e.CategoryId) + { + // The type id named a graphic style or a category element that has the category of the element, which replaced a + // voted type of another category. There is no such type: the voted one goes, and no other takes its place. + foreach (int pid in (ReadOnlySpan)[-1002050, -1002000, -1002052, -1002051]) + { + if (!parametersById.TryGetValue(pid, out var p) || p.FromNativeFields || p.Value is not int iv + || !elemById.TryGetValue(iv, out var currentType) || currentType.CategoryId == e.CategoryId) continue; + e.Parameters.Remove(p); + parametersById.Remove(pid); + e.TypeGuessOnNoType = e.TypeIdOnNoType; + } + } var refScan = ScanRefs(e, type?.References, isWall); int? materialId = refScan.MaterialId, coverTypeId = refScan.CoverTypeId, diff --git a/src/RvtIO/RvtDocument.cs b/src/RvtIO/RvtDocument.cs index aaf9d600..8abef1a4 100644 --- a/src/RvtIO/RvtDocument.cs +++ b/src/RvtIO/RvtDocument.cs @@ -132,6 +132,9 @@ private RvtDocument(RevitFileInfo info, string? sourcePath = null) /// private void SynthesizeMissingParams() { + // Graphic styles and category elements that the guess of an element named as its type: no type, but still the first + // element of their category that the guess of the elements after it finds, as a known type is. + var namedAsNoType = _info.Elements.Where(e => e.TypeGuessOnNoType > 0).Select(e => e.TypeGuessOnNoType).ToHashSet(); foreach (var elem in _info.Elements) { // ELEM_CATEGORY_PARAM is always available in the Revit API; synthesized from CategoryId. @@ -154,7 +157,10 @@ private void SynthesizeMissingParams() // ELEM_TYPE_PARAM for elements that don't have it but reference a type element: // walls often don't get it from the binary, but their References include the type ID. - if (elem.FamilyTypeId <= 0 && elem.References != null && elem.References.Count > 0) + // An element whose earlier guess named a graphic style or a category element has no type and gets no other guess; + // nor does a graphic style or a category element itself, which the file stores without one. + if (elem.FamilyTypeId <= 0 && elem.TypeGuessOnNoType == 0 && elem.NativeRecordClass is not (2050 or 632) + && elem.References != null && elem.References.Count > 0) { // Look for a referenced element with same category that: // a) is already known as a type (in _typeElementIds), OR @@ -167,7 +173,7 @@ private void SynthesizeMissingParams() if (refElem.CategoryId != elem.CategoryId) continue; // Known type element: best match - if (_typeElementIds.Contains(refId)) + if (_typeElementIds.Contains(refId) || namedAsNoType.Contains(refId)) { candidateTypeId = refId; break; @@ -175,13 +181,19 @@ private void SynthesizeMissingParams() // Same category, no bbox, no own type reference: likely a type definition if (candidateTypeId == null && (refElem.BoundingBox == null || refElem.BoundingBox.Length == 0) - && refElem.FamilyTypeId <= 0) + && refElem.FamilyTypeId <= 0 && refElem.TypeGuessOnNoType == 0) { candidateTypeId = refId; } } - if (candidateTypeId.HasValue) + // The best guess is a graphic style or a category element: that is no type, and no other element is put in its place. + if (candidateTypeId.HasValue && _elemById[candidateTypeId.Value].NativeRecordClass is 2050 or 632) + { + elem.TypeGuessOnNoType = candidateTypeId.Value; + namedAsNoType.Add(candidateTypeId.Value); + } + else if (candidateTypeId.HasValue) { elem.Parameters.Add(new Parameter { @@ -223,8 +235,13 @@ private void ResolveElementNames() // level whose ELEM_TYPE_PARAM resolves to a wall type was renamed to that type, e.g. "8mm Head"). if (elem.Category is "OST_Levels" or "OST_Views" or "OST_Grids" or "OST_Rooms" or "OST_Sheets" or "OST_Areas" or "OST_TextNotes") continue; - // A graphic style (GStyleElem, class 2050) has no type: a type link on it is a guess. - if (elem.NativeRecordClass == 2050) continue; + // A graphic style (GStyleElem, class 2050) and a category element (class 632) have no type: a type link on + // them is a guess. + if (elem.NativeRecordClass is 2050 or 632) continue; + // A material (MaterialElem, class 2486) is a document definition, not an instance: its type parameter is a guess and + // never gives it a name, as in the name pass of the reader. An element that only carries the category of materials, + // which it gets from what it refers to, is no material. + if (elem.NativeRecordClass is 2486) continue; int typeId = elem.FamilyTypeId; if (typeId <= 0) continue; if (!_elemById.TryGetValue(typeId, out var typeElem)) continue; diff --git a/tests/RvtIO.Tests/ApiTests.cs b/tests/RvtIO.Tests/ApiTests.cs index f95a40fd..861b06da 100644 --- a/tests/RvtIO.Tests/ApiTests.cs +++ b/tests/RvtIO.Tests/ApiTests.cs @@ -1095,12 +1095,15 @@ public void InvestigateNameStoragePattern() public void SearchBetonString() { // both counts include id 172544, a load case by its header that Revit does not return as an element; a graphic - // style has no name of its own here and is in neither - Assert.Equal(42, _doc.Elements.Count(e => e.Name != null && e.Name.Contains("Бетон"))); - Assert.Equal(49,_doc.Elements.Count(e => e.Name != null && e.Name.Contains("300"))); + // style and a category element have no name of their own here and are in neither: four category elements carried + // the name "Бетонный блок" of a neighbour, and two elements the name "900 x 300 мм" that they took through a link to one; + // a material keeps its own name, which it used to lose to the name of the element that its type link guessed + // ("Бетон - Железобетон" was "Бетон", "Бревна диаметром - 300мм" was a name without 300) + Assert.Equal(38, _doc.Elements.Count(e => e.Name != null && e.Name.Contains("Бетон"))); + Assert.Equal(48, _doc.Elements.Count(e => e.Name != null && e.Name.Contains("300"))); var material = _doc.GetElement(100935)!; Assert.Equal("OST_Materials", material.Category); - Assert.Equal("Бетон", material.Name); + Assert.Equal("Бетон - Железобетон", material.Name); var legend = _doc.GetElement(158904)!; Assert.Equal("OST_PreviewLegendComponents", legend.Category); Assert.Equal("Фундамент - Бетон 300мм", legend.Name); @@ -1890,8 +1893,9 @@ public void CheckWall290112() Assert.Equal(TypeName, type.Name); Assert.Equal("OST_Walls", type.Category); Assert.Equal([100907, 100928, 100935, 100940, 100941, 159011, 105725], type.References!); - Assert.Equal("Бетон", _doc.GetElement(100935)!.Name); - Assert.Equal("Гипсовый штукатурный раствор", _doc.GetElement(100941)!.Name); + // the names that the materials of the wall layers store, not the names of the elements that their type links guessed + Assert.Equal("Бетон - Железобетон", _doc.GetElement(100935)!.Name); + Assert.Equal("Штукатурка", _doc.GetElement(100941)!.Name); var wall = _doc.GetElement(290112); Console.WriteLine($"Wall 290112: Name={wall?.Name ?? "NULL"}, Cat={wall?.Category}, TypeId={wall?.TypeId}"); diff --git a/tests/RvtIO.Tests/CategoryElementNameTests.cs b/tests/RvtIO.Tests/CategoryElementNameTests.cs new file mode 100644 index 00000000..da96e724 --- /dev/null +++ b/tests/RvtIO.Tests/CategoryElementNameTests.cs @@ -0,0 +1,131 @@ +using RvtIO.Export; +using RvtIO.Internal; +using RvtIO.Model; +using RvtIO.Parsing; +using Xunit; + +namespace RvtIO.Tests; + +/// The name of a category element is the one the file stores for it; a name found near its id is another element's. +public class CategoryElementNameTests +{ + [Fact] + public void ResolveElementName_OfACategoryElement_IsItsStoredNameOrNone() + { + var state = new ParsingState(); + // every element has a string near its id and in its block, and a name the schema walk found + foreach (uint id in new uint[] { 30, 31, 32, 33, 34, 35 }) + { + state.ElemScanStrings[id] = ["Nearby"]; + state.ElemStrings[id] = ["In its block"]; + state.WideNames[id] = "From the schema walk"; + } + state.CategoryNames[30] = (1, ""); // the file stores no name for it + state.CategoryNames[31] = (1, "Layer A"); // the file stores its name + state.CategoryNames[32] = (2, null); // a repeated block says nothing + state.CategoryNames[33] = (1, null); // a block that did not decode says nothing + state.CategoryNames[34] = (1, ""); + state.ElementNameTable[34] = "Table name"; // the name table of the file is another source of own names + + Assert.Null(ElementBuilder.ResolveElementName(30, state)); + Assert.Equal("Layer A", ElementBuilder.ResolveElementName(31, state)); + Assert.Equal("From the schema walk", ElementBuilder.ResolveElementName(32, state)); + Assert.Equal("From the schema walk", ElementBuilder.ResolveElementName(33, state)); + Assert.Equal("Table name", ElementBuilder.ResolveElementName(34, state)); + // an element that is no category element keeps the names of the other sources + Assert.Equal("From the schema walk", ElementBuilder.ResolveElementName(35, state)); + } + + [Fact] + public void ResolveElementName_OfACategoryElementWithoutAStoredName_IgnoresTheStringsNearItsId() + { + var state = new ParsingState(); + foreach (uint id in new uint[] { 30, 31, 32, 33, 34 }) + { + state.ElemScanStrings[id] = ["Nearby"]; + state.ElemStrings[id] = ["In its block"]; + } + foreach (uint id in new uint[] { 30, 31, 32, 33 }) state.ElemClassIdx[id] = CategoryElementClass; + state.CategoryNames[30] = (2, null); // a repeated block says nothing + state.CategoryNames[31] = (1, null); // a block that did not decode says nothing + state.NativeElementNames[33] = "Own native name"; + // 32 has no entry at all; 34 is no category element + + Assert.Null(ElementBuilder.ResolveElementName(30, state)); + Assert.Null(ElementBuilder.ResolveElementName(31, state)); + Assert.Null(ElementBuilder.ResolveElementName(32, state)); + Assert.Equal("Own native name", ElementBuilder.ResolveElementName(33, state)); + Assert.NotNull(ElementBuilder.ResolveElementName(34, state)); + } + + private const ushort CategoryElementClass = 632; + + [Fact] + public void ValidatedName_OfACategoryElement_IsNeverThatOfALinkedType() + { + var type = new Element { Id = 11, ValidatedIfcTypeOwnName = "Type name" }; + var category = new Element { Id = 30, TypeId = 11, Parameters = [TypeParameter(11)] }; + var instance = new Element { Id = 40, TypeId = 11, Parameters = [TypeParameter(11)] }; + var byId = new[] { type, category, instance }.ToDictionary(element => element.Id); + var counts = byId.Keys.ToDictionary(id => id, _ => 1); + var state = new ParsingState(); + state.ElemClassIdx[30] = CategoryElementClass; + + Assert.Null(ValidatedElementNames.Resolve(category, byId, counts, state)); + Assert.Equal("Type name", ValidatedElementNames.Resolve(instance, byId, counts, state)?.Name); + } + + [Fact] + public void PostProcess_GivesACategoryElementNoTypeNameAndNoFamilyName() + { + var type = new Element { Id = 11, TypeId = -1, Name = "Type name" }; + var unnamed = new Element { Id = 30, TypeId = 11 }; + var byTypeParameter = new Element { Id = 31, TypeId = -1, Parameters = [TypeParameter(11)] }; + var named = new Element { Id = 32, TypeId = 11, Name = "Layer A" }; + var instance = new Element { Id = 40, TypeId = 11 }; + var info = new RevitFileInfo(); + info.Elements.AddRange([type, unnamed, byTypeParameter, named, instance]); + var state = new ParsingState(); + foreach (uint id in new uint[] { 30, 31, 32 }) state.ElemClassIdx[id] = CategoryElementClass; + state.ElementNameTable[11] = "Type name"; + // the name entry of the type leads to that of its family + state.NameEntryParentHolder[11] = 1; + state.NameHolderTarget[1] = 2; + state.ElementNameTable[2] = "Family"; + + ElementBuilder.PostProcess(info, state); + + Assert.Null(unnamed.Name); + Assert.Null(byTypeParameter.Name); + Assert.Equal("Layer A", named.Name); + Assert.Equal("Type name", instance.Name); + Assert.Null(unnamed.FamilyName); + Assert.Null(byTypeParameter.FamilyName); + Assert.Null(named.FamilyName); + Assert.Equal("Family", instance.FamilyName); + } + + [Fact] + public void Document_GivesACategoryElementNoTypeNameAndNoFamilyName() + { + var type = new Element { Id = 11, TypeId = -1, Name = "Type name", FamilyName = "Family" }; + var unnamed = new Element { Id = 30, NativeRecordClass = CategoryElementClass, Parameters = [TypeParameter(11)] }; + var named = new Element { Id = 31, Name = "Layer A", NativeRecordClass = CategoryElementClass, Parameters = [TypeParameter(11)] }; + var instance = new Element { Id = 40, Parameters = [TypeParameter(11)] }; + var info = new RevitFileInfo(); + info.Elements.AddRange([type, unnamed, named, instance]); + + // the document works on copies of the elements + var copies = RvtDocument.FromInfo(info).Elements.ToDictionary(element => element.Id); + + Assert.Null(copies[30].Name); + Assert.Null(copies[30].FamilyName); + Assert.Equal("Layer A", copies[31].Name); + Assert.Null(copies[31].FamilyName); + Assert.Equal("Type name", copies[40].Name); + Assert.Equal("Family", copies[40].FamilyName); + } + + private static Parameter TypeParameter(int typeId) => + BipHelpers.MakeBipParam(-1002050, "ELEM_TYPE_PARAM", StorageType.ElementId, typeId); +} diff --git a/tests/RvtIO.Tests/NoTypeDocumentGuessTests.cs b/tests/RvtIO.Tests/NoTypeDocumentGuessTests.cs new file mode 100644 index 00000000..fe02e183 --- /dev/null +++ b/tests/RvtIO.Tests/NoTypeDocumentGuessTests.cs @@ -0,0 +1,171 @@ +using RvtIO.Model; +using Xunit; + +namespace RvtIO.Tests; + +/// +/// The type that a document gives an element without one from the elements it refers to is never a graphic style or a category +/// element, and an element whose earlier guess named one of them stays without a type instead of getting another. +/// +public class NoTypeDocumentGuessTests +{ + private const int DuctsCategory = -2008000; + + private static Element Duct(int id, params int[] references) => + new() { Id = id, TypeId = -1, CategoryId = DuctsCategory, Category = "OST_DuctCurves", References = [.. references] }; + + private static int? TypeParameter(Element element) => + element.Parameters.FirstOrDefault(parameter => parameter.DefinitionName == "ELEM_TYPE_PARAM")?.Value as int?; + + private static IReadOnlyDictionary Open(params Element[] elements) + { + var info = new RevitFileInfo(); + info.Elements.AddRange(elements); + return RvtDocument.FromInfo(info).Elements.ToDictionary(element => element.Id); + } + + [Fact] + public void FromInfo_GivesAnElementWithoutTypeTheElementItRefersToAsItsType() + { + var type = Duct(2001); + var duct = Duct(2003, 2001); + + var elements = Open(type, duct); + + Assert.Equal(2001, TypeParameter(elements[2003])); + } + + [Fact] + public void FromInfo_GivesNoOtherTypeToAnElementWhoseGuessWasNoType() + { + var type = Duct(2001); + var duct = Duct(2003, 2001); + duct.TypeGuessOnNoType = 2005; + + var elements = Open(type, duct); + + Assert.Null(TypeParameter(elements[2003])); + } + + [Fact] + public void FromInfo_TakesNoElementWhoseGuessWasNoTypeAsATypeOfAnother() + { + var flagged = Duct(2002); + flagged.TypeGuessOnNoType = 2005; + var duct = Duct(2003, 2002); + + var elements = Open(flagged, duct); + + Assert.Null(TypeParameter(elements[2003])); + } + + [Fact] + public void FromInfo_KeepsTheStyleAKnownTypeToTheElementsAfterTheOneThatNamedIt() + { + // the first duct names the style as its type, which makes the style a known type to the guess of the second duct; + // that duct finds it before the other element of its category, as it always did, and so has no type + var style = Duct(2005); + style.NativeRecordClass = 2050; + var other = Duct(2001); + var first = Duct(2006, 2005); + var second = Duct(2008, 2001, 2005); + + var elements = Open(style, other, first, second); + + Assert.Null(TypeParameter(elements[2006])); + Assert.Null(TypeParameter(elements[2008])); + Assert.Equal(2005, elements[2008].TypeGuessOnNoType); + } + + [Fact] + public void FromInfo_KeepsTheStyleAKnownTypeToTheElementsAfterTheOneWhoseEarlierGuessNamedIt() + { + // the vote of the first duct named the style before: it counts as a known type here too + var style = Duct(2005); + style.NativeRecordClass = 2050; + var other = Duct(2001); + var first = Duct(2006); + first.TypeGuessOnNoType = 2005; + var second = Duct(2008, 2001, 2005); + + var elements = Open(style, other, first, second); + + Assert.Null(TypeParameter(elements[2008])); + Assert.Equal(2005, elements[2008].TypeGuessOnNoType); + } + + [Fact] + public void FromInfo_GivesAStyleAndACategoryElementNoTypeFromTheElementsTheyRefer() + { + // the file stores no type for either: the element they refer to is a guess about something that has no type + var type = Duct(2001); + var style = Duct(2005, 2001); + style.NativeRecordClass = 2050; + var categoryElement = Duct(2007, 2001); + categoryElement.NativeRecordClass = 632; + var duct = Duct(2003, 2001); + // nothing but a style names this one, so it is no type of anything + var namedByStyleOnly = Duct(2011); + var styleOfIt = Duct(2013, 2011); + styleOfIt.NativeRecordClass = 2050; + var info = new RevitFileInfo(); + info.Elements.AddRange([type, style, categoryElement, duct, namedByStyleOnly, styleOfIt]); + + var document = RvtDocument.FromInfo(info); + var elements = document.Elements.ToDictionary(element => element.Id); + + Assert.Equal(2001, TypeParameter(elements[2003])); + Assert.Null(TypeParameter(elements[2005])); + Assert.Null(TypeParameter(elements[2007])); + Assert.Null(TypeParameter(elements[2013])); + Assert.Contains(2001, document.TypeElementIds); + Assert.DoesNotContain(2011, document.TypeElementIds); + } + + [Fact] + public void FromInfo_KeepsTheAuthoredNameOfAMaterialWhoseTypeParameterNamesAnotherElement() + { + // a material is a document definition, not an instance: the element its type parameter points at never gives it its + // name, as in the name pass of the reader + var type = Duct(2001); + type.Name = "Typical"; + var material = new Element { Id = 2020, TypeId = -1, CategoryId = -2000700, Category = "OST_Materials", Name = "Authored", NativeRecordClass = 2486 }; + material.Parameters.Add(Parsing.BipHelpers.MakeBipParam(-1002050, "ELEM_TYPE_PARAM", StorageType.ElementId, 2001)); + + var elements = Open(type, material); + + Assert.Equal("Authored", elements[2020].Name); + } + + [Fact] + public void FromInfo_GivesAnElementThatOnlyCarriesTheCategoryOfMaterialsTheNameOfItsType() + { + // an element gets this category from what it refers to, and is a material only when the file stores it as one + var type = Duct(2001); + type.Name = "Typical"; + var instance = new Element { Id = 2020, TypeId = -1, CategoryId = -2000700, Category = "OST_Materials", Name = "Own", NativeRecordClass = 1926 }; + instance.Parameters.Add(Parsing.BipHelpers.MakeBipParam(-1002050, "ELEM_TYPE_PARAM", StorageType.ElementId, 2001)); + + var elements = Open(type, instance); + + Assert.Equal("Typical", elements[2020].Name); + } + + [Fact] + public void FromInfo_TakesNoStyleOrCategoryElementAsTheTypeOfAnElement() + { + var style = Duct(2005); + style.NativeRecordClass = 2050; + var categoryElement = Duct(2007); + categoryElement.NativeRecordClass = 632; + var ofStyle = Duct(2006, 2005); + var ofCategoryElement = Duct(2008, 2007); + + var elements = Open(style, categoryElement, ofStyle, ofCategoryElement); + + Assert.Null(TypeParameter(elements[2006])); + Assert.Null(TypeParameter(elements[2008])); + Assert.Equal(2005, elements[2006].TypeGuessOnNoType); + Assert.Equal(2007, elements[2008].TypeGuessOnNoType); + } +} diff --git a/tests/RvtIO.Tests/NoTypeElementLinkTests.cs b/tests/RvtIO.Tests/NoTypeElementLinkTests.cs new file mode 100644 index 00000000..92415672 --- /dev/null +++ b/tests/RvtIO.Tests/NoTypeElementLinkTests.cs @@ -0,0 +1,428 @@ +using RvtIO.Internal; +using RvtIO.Model; +using RvtIO.Parsing; +using Xunit; + +namespace RvtIO.Tests; + +/// +/// A graphic style and a category element are no type, no material and no fill pattern. The guess of the type of an element that +/// lands on one of them makes no type (the other guesses stay as they were), and an element is a material or a fill pattern only +/// when the file stores it so. +/// +public class NoTypeElementLinkTests +{ + private const ushort GraphicStyleClass = 2050, CategoryElementClass = 632, FillPatternClass = 1851, MaterialClass = 2486; + private const int WallsCategory = -2000011, MaterialsCategory = -2000700, DuctsCategory = -2008000; + + private static Element WithCategory(Element element, int categoryId, string category) + { + element.CategoryId = categoryId; + element.Category = category; + return element; + } + + private static ParsingState StateOf(params (uint Id, ushort Class)[] classes) + { + var state = new ParsingState(); + foreach (var (id, elementClass) in classes) state.ElemClassIdx[id] = elementClass; + return state; + } + + private static Parameter TypeParameter(int typeId) => + BipHelpers.MakeBipParam(-1002050, "ELEM_TYPE_PARAM", StorageType.ElementId, typeId); + + private static bool HasTypeParameter(Element element) => element.Parameters.Any(parameter => parameter.Id == -1002050); + + [Fact] + public void PostProcess_GivesAnElementNoStyleOrCategoryElementAsItsTypeId() + { + // the category element and the style carry the category of the duct; the file stores them without one + var categoryElement = WithCategory(new Element { Id = 5, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var style = WithCategory(new Element { Id = 6, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var type = WithCategory(new Element { Id = 4, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var laterType = WithCategory(new Element { Id = 11, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + // the lowest id among the references that carry its category decides, as it always did + var ductOfType = WithCategory(new Element { Id = 40, TypeId = -1, References = [4, 5, 6] }, DuctsCategory, "OST_DuctCurves"); + var ductOfCategoryElement = WithCategory(new Element { Id = 41, TypeId = -1, References = [5, 6, 11] }, DuctsCategory, "OST_DuctCurves"); + var byParameter = WithCategory(new Element { Id = 42, TypeId = -1, Parameters = [TypeParameter(5)] }, DuctsCategory, "OST_DuctCurves"); + var info = new RevitFileInfo(); + info.Elements.AddRange([categoryElement, style, type, laterType, ductOfType, ductOfCategoryElement, byParameter]); + var state = StateOf((5, CategoryElementClass), (6, GraphicStyleClass)); + + ElementBuilder.PostProcess(info, state); + + Assert.Equal(4, ductOfType.TypeId); + Assert.Equal(-1, ductOfCategoryElement.TypeId); // none, and not the type that comes after the category element + Assert.Equal(-1, byParameter.TypeId); + } + + [Fact] + public void PostProcess_VotesTheTypeParametersOfAnElementWhoseTypeIdGuessWasAStyleOrCategoryElement() + { + // 1011 is a known type: a duct carries it. The duct that refers to the category element has no type id, and the + // references still vote for its type parameters + var categoryElement = WithCategory(new Element { Id = 1005, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var type = WithCategory(new Element { Id = 1011, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var carrier = WithCategory(new Element { Id = 1039, TypeId = -1, Parameters = [TypeParameter(1011)] }, DuctsCategory, "OST_DuctCurves"); + var ductOfCategoryElement = WithCategory(new Element { Id = 1040, TypeId = -1, References = [1005, 1011] }, DuctsCategory, "OST_DuctCurves"); + var ductOfType = WithCategory(new Element { Id = 1041, TypeId = -1, References = [1011] }, DuctsCategory, "OST_DuctCurves"); + var info = new RevitFileInfo(); + info.Elements.AddRange([categoryElement, type, carrier, ductOfCategoryElement, ductOfType]); + var state = StateOf((1005, CategoryElementClass)); + + ElementBuilder.PostProcess(info, state); + + Assert.Equal(-1, ductOfCategoryElement.TypeId); + Assert.Equal(1011, ductOfCategoryElement.Parameters.Single(parameter => parameter.Id == -1002050).Value); + Assert.Equal(0, ductOfCategoryElement.TypeGuessOnNoType); + Assert.Equal(1011, ductOfType.TypeId); + } + + [Fact] + public void PostProcess_KeepsTheStyleAKnownTypeWhereItWouldHaveReplacedTheValueOfATypeParameter() + { + // the type parameter of the carrier holds a value that is no element; its type id guess lands on the style, which the + // parameter used to take as its value and so made a known type. The duct that refers to the type first and to the style + // after it votes for the known style as before and so gets no type, instead of the type that comes first + var style = WithCategory(new Element { Id = 1005, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var type = WithCategory(new Element { Id = 1011, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var carrier = WithCategory(new Element { Id = 1030, TypeId = -1, References = [1005], Parameters = [TypeParameter(528)] }, DuctsCategory, "OST_DuctCurves"); + var bothTypesRefer = WithCategory(new Element { Id = 1040, TypeId = -1, References = [1011, 1005] }, DuctsCategory, "OST_DuctCurves"); + var ofType = WithCategory(new Element { Id = 1041, TypeId = -1, References = [1011] }, DuctsCategory, "OST_DuctCurves"); + var info = new RevitFileInfo(); + info.Elements.AddRange([style, type, carrier, bothTypesRefer, ofType]); + var state = StateOf((1005, GraphicStyleClass)); + + ElementBuilder.PostProcess(info, state); + + Assert.False(HasTypeParameter(bothTypesRefer)); + Assert.Equal(1005, bothTypesRefer.TypeGuessOnNoType); + Assert.Equal(1011, ofType.Parameters.Single(parameter => parameter.Id == -1002050).Value); + } + + [Fact] + public void PostProcess_DoesNotLetAStyleTypeIdReplaceTheVotedTypeParameters() + { + // the vote of the wall gives 1011, which has no category; the type id guess lands on the style that has the category of the + // wall, which used to replace the voted type because it improved the category. There is no such type, so the wall has none + var style = WithCategory(new Element { Id = 1005, TypeId = -1 }, WallsCategory, "OST_Walls"); + var votedType = new Element { Id = 1011, TypeId = -1 }; + var carrier = WithCategory(new Element { Id = 1030, TypeId = -1, Parameters = [TypeParameter(1011)] }, WallsCategory, "OST_Walls"); + var wall = WithCategory(new Element { Id = 1040, TypeId = -1, References = [1005, 1011] }, WallsCategory, "OST_Walls"); + // the same wall where the style has no category of its own: the type id does not improve the category, the vote stands + var styleWithoutCategory = new Element { Id = 1006, TypeId = -1 }; + var otherWall = WithCategory(new Element { Id = 1041, TypeId = -1, References = [1006, 1011] }, WallsCategory, "OST_Walls"); + var info = new RevitFileInfo(); + info.Elements.AddRange([style, votedType, carrier, wall, styleWithoutCategory, otherWall]); + var state = StateOf((1005, GraphicStyleClass), (1006, GraphicStyleClass)); + + ElementBuilder.PostProcess(info, state); + + Assert.Equal(-1, wall.TypeId); + Assert.False(HasTypeParameter(wall)); + Assert.Equal(1005, wall.TypeGuessOnNoType); + Assert.Equal(1011, otherWall.Parameters.Single(parameter => parameter.Id == -1002050).Value); + } + + [Fact] + public void PostProcess_MakesNoFamilyParameterWhereTheVoteLandedOnAStyleAndTheTypeIdIsBelow1000() + { + // the type id (29) is the only reference that carries the category of the walls; the references vote for the style, which + // has none, so the type parameters follow the type id. The family parameter is made only from a type above 1000, which + // the vote used to give (the style) and the type id does not: the file stores the family parameter when there is one, and + // the walls get none made up + var type = WithCategory(new Element { Id = 29, TypeId = -1 }, WallsCategory, "OST_Walls"); + var style = new Element { Id = 1005, TypeId = -1 }; + var walls = Enumerable.Range(1040, 2).Select(id => WithCategory( + new Element { Id = id, TypeId = -1, References = [29, 1005] }, WallsCategory, "OST_Walls")).ToArray(); + var info = new RevitFileInfo(); + info.Elements.AddRange(walls); + info.Elements.AddRange([type, style]); + var state = StateOf((1005, GraphicStyleClass)); + + ElementBuilder.PostProcess(info, state); + + Assert.All(walls, wall => Assert.Equal(29, wall.TypeId)); + Assert.All(walls, wall => Assert.Equal(29, wall.Parameters.Single(parameter => parameter.Id == -1002050).Value)); + Assert.All(walls, wall => Assert.DoesNotContain(wall.Parameters, parameter => parameter.Id == -1002051)); + } + + [Fact] + public void ResolveTypeParams_TakesNoStyleOrCategoryElementAsTheTypeOfAnElement() + { + // walls refer to a style, a category element and the type of the walls; the references vote and the style comes first + var style = new Element { Id = 1001 }; + var categoryElement = new Element { Id = 1002 }; + var wallType = WithCategory(new Element { Id = 1003 }, WallsCategory, "OST_Walls"); + var walls = Enumerable.Range(1, 3).Select(id => WithCategory( + new Element { Id = id, References = [1001, 1002, 1003] }, WallsCategory, "OST_Walls")).ToArray(); + // walls whose references vote for the type first + var typeFirst = Enumerable.Range(4, 3).Select(id => WithCategory( + new Element { Id = id, References = [1003, 1001] }, WallsCategory, "OST_Walls")).ToArray(); + var info = new RevitFileInfo(); + info.Elements.AddRange(walls); + info.Elements.AddRange(typeFirst); + info.Elements.AddRange([style, categoryElement, wallType]); + var state = StateOf((1001, GraphicStyleClass), (1002, CategoryElementClass)); + + ElementBuilder.ResolveTypeParams(info, info.Elements.ToDictionary(element => element.Id), state); + + Assert.All(walls, wall => Assert.False(HasTypeParameter(wall))); + Assert.All(walls, wall => Assert.Equal(1001, wall.TypeGuessOnNoType)); + Assert.All(typeFirst, wall => Assert.Equal(1003, wall.Parameters.Single(parameter => parameter.Id == -1002050).Value)); + Assert.All(typeFirst, wall => Assert.Equal(0, wall.TypeGuessOnNoType)); + } + + [Fact] + public void ResolveTypeParams_FollowsTheTypeIdOfAnElementWhoseVoteLandsOnAStyle() + { + // the references of all walls vote for the style, which comes first; the type id of one wall names a type of walls + var style = new Element { Id = 1001 }; + var wallType = WithCategory(new Element { Id = 1003 }, WallsCategory, "OST_Walls"); + var withTypeId = WithCategory(new Element { Id = 1, TypeId = 1003, References = [1001, 1003] }, WallsCategory, "OST_Walls"); + var withoutTypeId = WithCategory(new Element { Id = 2, TypeId = -1, References = [1001, 1003] }, WallsCategory, "OST_Walls"); + var info = new RevitFileInfo(); + info.Elements.AddRange([style, wallType, withTypeId, withoutTypeId]); + var state = StateOf((1001, GraphicStyleClass)); + + ElementBuilder.ResolveTypeParams(info, info.Elements.ToDictionary(element => element.Id), state); + + Assert.Equal(1003, withTypeId.Parameters.Single(parameter => parameter.Id == -1002050).Value); + Assert.Equal(0, withTypeId.TypeGuessOnNoType); + Assert.False(HasTypeParameter(withoutTypeId)); + Assert.Equal(1001, withoutTypeId.TypeGuessOnNoType); + } + + [Fact] + public void ResolveTypeParams_DoesNotFollowTheTypeIdWhereTheStyleHasTheCategoryOfTheElement() + { + // the style carries the category of the walls, so the type id does not improve the category of the guess + var style = WithCategory(new Element { Id = 1001 }, WallsCategory, "OST_Walls"); + var wallType = WithCategory(new Element { Id = 1003 }, WallsCategory, "OST_Walls"); + var walls = Enumerable.Range(1, 3).Select(id => WithCategory( + new Element { Id = id, TypeId = 1003, References = [1001, 1003] }, WallsCategory, "OST_Walls")).ToArray(); + var info = new RevitFileInfo(); + info.Elements.AddRange(walls); + info.Elements.AddRange([style, wallType]); + var state = StateOf((1001, GraphicStyleClass)); + + ElementBuilder.ResolveTypeParams(info, info.Elements.ToDictionary(element => element.Id), state); + + Assert.All(walls, wall => Assert.False(HasTypeParameter(wall))); + Assert.All(walls, wall => Assert.Equal(1001, wall.TypeGuessOnNoType)); + } + + [Fact] + public void ResolveTypeParams_DoesNotFollowATypeIdThatIsNoTypeOfTheCategoryOfTheElement() + { + // the type id of the walls names an element that has no category: it is no type of walls, and the later fix of the type + // parameters would not put it in the place of the style either, so the walls have none + var style = new Element { Id = 1001 }; + var notAType = new Element { Id = 1003 }; + var walls = Enumerable.Range(1, 2).Select(id => WithCategory( + new Element { Id = id, TypeId = 1003, References = [1001, 1003] }, WallsCategory, "OST_Walls")).ToArray(); + var info = new RevitFileInfo(); + info.Elements.AddRange(walls); + info.Elements.AddRange([style, notAType]); + var state = StateOf((1001, GraphicStyleClass)); + + ElementBuilder.ResolveTypeParams(info, info.Elements.ToDictionary(element => element.Id), state); + + Assert.All(walls, wall => Assert.False(HasTypeParameter(wall))); + Assert.All(walls, wall => Assert.Equal(1001, wall.TypeGuessOnNoType)); + } + + [Fact] + public void ResolveTypeParams_TakesNoStyleAsTheDimensionStyleOfAWeakDimension() + { + // a weak dimension takes the first thing it refers to as its type; it does not take a style + var style = new Element { Id = 277 }; + var dimensionStyle = new Element { Id = 278 }; + var byStyle = WithCategory(new Element { Id = 1, References = [277] }, -2000261, "OST_Dimensions"); + var byDimensionStyle = WithCategory(new Element { Id = 2, References = [278] }, -2000261, "OST_Dimensions"); + // 1003 is a known type (another dimension carries it); the guess of this dimension stops at the style + var carrier = WithCategory(new Element { Id = 3, Parameters = [TypeParameter(1003)] }, -2000261, "OST_Dimensions"); + var byStyleThenType = WithCategory(new Element { Id = 4, References = [277, 1003] }, -2000261, "OST_Dimensions"); + var info = new RevitFileInfo(); + info.Elements.AddRange([style, dimensionStyle, byStyle, byDimensionStyle, carrier, byStyleThenType]); + var state = StateOf((277, GraphicStyleClass)); + + ElementBuilder.ResolveTypeParams(info, info.Elements.ToDictionary(element => element.Id), state); + + Assert.False(HasTypeParameter(byStyle)); + Assert.False(HasTypeParameter(byStyleThenType)); // the vote does not take another type in the style's place + Assert.Equal(277, byStyle.TypeGuessOnNoType); + Assert.Equal(277, byStyleThenType.TypeGuessOnNoType); + Assert.Equal(278, byDimensionStyle.Parameters.Single(parameter => parameter.Id == -1002050).Value); + } + + [Fact] + public void ResolveTypeParams_TakesNoStyleAsTheKnownTypeOfAnElementWithoutCategory() + { + // another element names the style as its type parameter, which makes it a known type; it stays no type for the element + var style = new Element { Id = 1001 }; + var wallType = WithCategory(new Element { Id = 1003 }, WallsCategory, "OST_Walls"); + var carrier = WithCategory(new Element { Id = 1, Parameters = [TypeParameter(1001)] }, WallsCategory, "OST_Walls"); + var wall = WithCategory(new Element { Id = 2, Parameters = [TypeParameter(1003)] }, WallsCategory, "OST_Walls"); + var onlyTheStyle = new Element { Id = 1002, References = [1001] }; + var theTypeOfWalls = new Element { Id = 1004, References = [1003] }; + var info = new RevitFileInfo(); + info.Elements.AddRange([style, wallType, carrier, wall, onlyTheStyle, theTypeOfWalls]); + var state = StateOf((1001, GraphicStyleClass)); + + ElementBuilder.ResolveTypeParams(info, info.Elements.ToDictionary(element => element.Id), state); + + Assert.False(HasTypeParameter(onlyTheStyle)); + // an element of another kind keeps taking the known type + Assert.Equal(1003, theTypeOfWalls.Parameters.Single(parameter => parameter.Id == -1002050).Value); + } + + [Fact] + public void PostProcess_TakesNoGraphicStyleAsTheMaterialOfAWall() + { + var material = WithCategory(new Element { Id = 12, TypeId = -1 }, MaterialsCategory, "OST_Materials"); + var materialLike = WithCategory(new Element { Id = 13, TypeId = -1 }, MaterialsCategory, "OST_Materials"); + // the style takes the category of the element its type guess names, and then counts as a material by category + var style = new Element { Id = 30, TypeId = 13 }; + var wall = WithCategory(new Element { Id = 40, TypeId = -1, References = [30, 12] }, WallsCategory, "OST_Walls"); + var info = new RevitFileInfo(); + info.Elements.AddRange([material, materialLike, style, wall]); + var state = StateOf((12, 2486), (30, GraphicStyleClass)); + + ElementBuilder.PostProcess(info, state); + + Assert.Equal(12, wall.Parameters.Single(parameter => parameter.Id == -1005500).Value); + } + + [Fact] + public void EnrichTypeLevelBips_TakesAsMaterialOnlyAMaterialElement() + { + // an element carries the category of materials when the elements it refers to do; that makes it no material + var carrier = WithCategory(new Element { Id = 20, TypeId = -1, Name = "Arrow 1" }, MaterialsCategory, "OST_Materials"); + var material = WithCategory(new Element { Id = 21, TypeId = -1, Name = "Concrete" }, MaterialsCategory, "OST_Materials"); + var onlyCarrier = WithCategory(new Element { Id = 50, TypeId = -1, References = [20] }, WallsCategory, "OST_Walls"); + var withMaterial = WithCategory(new Element { Id = 51, TypeId = -1, References = [20, 21] }, WallsCategory, "OST_Walls"); + var elements = new[] { carrier, material, onlyCarrier, withMaterial }; + var info = new RevitFileInfo(); + info.Elements.AddRange(elements); + var state = StateOf((20, 3972), (21, MaterialClass)); + + ElementBuilder.EnrichTypeLevelBips(info, state, elements.ToDictionary(element => element.Id)); + + Assert.DoesNotContain(onlyCarrier.Parameters, parameter => parameter.Id == -1005500); + Assert.Equal(21, withMaterial.Parameters.Single(parameter => parameter.Id == -1005500).Value); + } + + [Fact] + public void EnrichTypeLevelBips_TakesAsFillPatternOnlyAFillPatternElement() + { + // named elements without a category in the id range of the old guess: a dimension style and a parameter element + var dimensionStyle = new Element { Id = 277, TypeId = -1, Name = "Arrow 1" }; + var parameterElement = new Element { Id = 3000, TypeId = -1, Name = "Floor number" }; + var fillPattern = new Element { Id = 442, TypeId = -1, Name = "Concrete" }; + var onlyOthers = WithCategory(new Element { Id = 50, TypeId = -1, References = [277, 3000] }, WallsCategory, "OST_Walls"); + var withFillPattern = WithCategory(new Element { Id = 51, TypeId = -1, References = [277, 3000, 442] }, WallsCategory, "OST_Walls"); + var elements = new[] { dimensionStyle, parameterElement, fillPattern, onlyOthers, withFillPattern }; + var info = new RevitFileInfo(); + info.Elements.AddRange(elements); + var state = StateOf((277, 174), (3000, 2873), (442, FillPatternClass)); + + ElementBuilder.EnrichTypeLevelBips(info, state, elements.ToDictionary(element => element.Id)); + + Assert.DoesNotContain(onlyOthers.Parameters, parameter => parameter.Id == -1002106); + Assert.Equal(442, withFillPattern.Parameters.Single(parameter => parameter.Id == -1002106).Value); + } + + [Fact] + public void EnrichTypeLevelBips_RemovesAVotedTypeOfAnotherCategoryOnlyWhereTheStyleOfTheTypeIdHasTheCategoryOfTheElement() + { + // 1011 is a voted type of ducts. The type id of the first wall named a style that has no category of walls: the type id + // would not have replaced the voted type, so it stays. The style of the second wall has the category of walls: the type id + // would have replaced the voted type, so there is none now, and no other takes its place + var voted = WithCategory(new Element { Id = 1011, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var styleOfDucts = WithCategory(new Element { Id = 1005, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var styleOfWalls = WithCategory(new Element { Id = 1006, TypeId = -1 }, WallsCategory, "OST_Walls"); + var keeps = WithCategory(new Element { Id = 50, TypeId = -1, Parameters = [TypeParameter(1011)] }, WallsCategory, "OST_Walls"); + keeps.TypeIdOnNoType = 1005; + var loses = WithCategory(new Element { Id = 51, TypeId = -1, Parameters = [TypeParameter(1011)] }, WallsCategory, "OST_Walls"); + loses.TypeIdOnNoType = 1006; + var elements = new[] { voted, styleOfDucts, styleOfWalls, keeps, loses }; + var info = new RevitFileInfo(); + info.Elements.AddRange(elements); + var state = StateOf((1005, GraphicStyleClass), (1006, GraphicStyleClass)); + + ElementBuilder.EnrichTypeLevelBips(info, state, elements.ToDictionary(element => element.Id)); + + Assert.Equal(1011, keeps.Parameters.Single(parameter => parameter.Id == -1002050).Value); + Assert.Equal(0, keeps.TypeGuessOnNoType); + Assert.False(HasTypeParameter(loses)); + Assert.Equal(1006, loses.TypeGuessOnNoType); + } + + [Fact] + public void EnrichTypeLevelBips_KeepsATypeParameterThatTheFileStoresWhereTheTypeIdNamedAStyle() + { + // what the file stores in the fields of an element stays as it was read, also where the type id named a style + var voted = WithCategory(new Element { Id = 1011, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var styleOfWalls = WithCategory(new Element { Id = 1006, TypeId = -1 }, WallsCategory, "OST_Walls"); + var parameter = TypeParameter(1011); + parameter.FromNativeFields = true; + var wall = WithCategory(new Element { Id = 50, TypeId = -1, Parameters = [parameter] }, WallsCategory, "OST_Walls"); + wall.TypeIdOnNoType = 1006; + var elements = new[] { voted, styleOfWalls, wall }; + var info = new RevitFileInfo(); + info.Elements.AddRange(elements); + var state = StateOf((1006, GraphicStyleClass)); + + ElementBuilder.EnrichTypeLevelBips(info, state, elements.ToDictionary(element => element.Id)); + + Assert.Equal(1011, wall.Parameters.Single(candidate => candidate.Id == -1002050).Value); + Assert.Equal(0, wall.TypeGuessOnNoType); + } + + [Fact] + public void PostProcess_GivesAStyleAndACategoryElementNoTypeIdAndNoTypeParametersFromTheirReferences() + { + // the file stores no type for a graphic style or a category element: what the references of one would give it (the type id + // of the lowest same-category reference, the vote of the type parameters, the family parameter that follows) is a guess + // about something that has no type, while an element that is not one of them gets the same guess as ever + var type = WithCategory(new Element { Id = 1011, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var carrier = WithCategory(new Element { Id = 1039, TypeId = -1, Parameters = [TypeParameter(1011)] }, DuctsCategory, "OST_DuctCurves"); + var style = WithCategory(new Element { Id = 1040, TypeId = -1, References = [1011, 1040] }, DuctsCategory, "OST_DuctCurves"); + var categoryElement = WithCategory(new Element { Id = 1041, TypeId = -1, References = [1011, 1041] }, DuctsCategory, "OST_DuctCurves"); + var duct = WithCategory(new Element { Id = 1042, TypeId = -1, References = [1011] }, DuctsCategory, "OST_DuctCurves"); + var info = new RevitFileInfo(); + info.Elements.AddRange([type, carrier, style, categoryElement, duct]); + var state = StateOf((1040, GraphicStyleClass), (1041, CategoryElementClass)); + + ElementBuilder.PostProcess(info, state); + + Assert.Equal(1011, duct.TypeId); + Assert.Equal(1011, duct.Parameters.Single(parameter => parameter.Id == -1002050).Value); + foreach (var noType in new[] { style, categoryElement }) + { + Assert.Equal(-1, noType.TypeId); + Assert.DoesNotContain(noType.Parameters, parameter => parameter.Id is -1002050 or -1002000 or -1002052 or -1002051); + } + } + + [Fact] + public void PostProcess_KeepsTheFamilyThatTheFileStoresOnAStyle() + { + // m_famId of the record is what the file stores: the family parameter of a style is the family that owns it + var family = WithCategory(new Element { Id = 1011, TypeId = -1 }, DuctsCategory, "OST_DuctCurves"); + var familyParameter = BipHelpers.MakeBipParam(-1002051, "ELEM_FAMILY_PARAM", StorageType.ElementId, 1011); + familyParameter.FromNativeFields = true; + var style = WithCategory(new Element { Id = 1040, TypeId = -1, References = [1011, 1040], Parameters = [familyParameter] }, + DuctsCategory, "OST_DuctCurves"); + var info = new RevitFileInfo(); + info.Elements.AddRange([family, style]); + + ElementBuilder.PostProcess(info, StateOf((1040, GraphicStyleClass))); + + Assert.Equal(-1, style.TypeId); + Assert.Equal(1011, style.Parameters.Single(parameter => parameter.Id == -1002051).Value); + Assert.DoesNotContain(style.Parameters, parameter => parameter.Id is -1002050 or -1002000 or -1002052); + } +} diff --git a/tests/RvtIO.Tests/WallThermalFallbackProvenanceTests.cs b/tests/RvtIO.Tests/WallThermalFallbackProvenanceTests.cs index 729a5d52..fe9ffa82 100644 --- a/tests/RvtIO.Tests/WallThermalFallbackProvenanceTests.cs +++ b/tests/RvtIO.Tests/WallThermalFallbackProvenanceTests.cs @@ -13,6 +13,14 @@ public class WallThermalFallbackProvenanceTests private static void Enrich(RevitFileInfo info, ParsingState? state) => ElementBuilder.EnrichTypeLevelBips(info, state, info.Elements.ToDictionary(element => element.Id)); + // the file stores the material of the model as a material element (class 2486) + private static ParsingState StateWithMaterial() + { + var state = new ParsingState(); + state.ElemClassIdx[20] = 2486; + return state; + } + private static (RevitFileInfo Info, Element Wall) Model() { var wall = new Element { Id = 10, CategoryId = -2000011, References = [20], @@ -29,7 +37,7 @@ public void EnrichUsesTheFirstParameterWhenTheSameIdOccursTwice() var second = BipHelpers.MakeBipParam(-1005500, "STRUCTURAL_MATERIAL_PARAM", StorageType.ElementId, -2); wall.Parameters.AddRange([first, second]); - Enrich(info, new ParsingState()); + Enrich(info, StateWithMaterial()); Assert.Equal(20, first.Value); Assert.Equal(-2, second.Value); @@ -43,7 +51,7 @@ public void CommonDefaultsRetainStoredValuesAndAppendInRuleOrder() var stored = BipHelpers.MakeBipParam(-1010104, "ALL_MODEL_URL", StorageType.String, "stored"); wall.Parameters.Add(stored); - Enrich(info, new ParsingState()); + Enrich(info, StateWithMaterial()); Assert.Same(stored, Assert.Single(wall.Parameters, parameter => parameter.Id == -1010104)); Assert.Equal("stored", stored.Value); @@ -58,7 +66,7 @@ public void CommonDefaultsRetainStoredValuesAndAppendInRuleOrder() public void CommonDefaultDefinitionsCanBeEditedIndependently() { var (info, wall) = Model(); - Enrich(info, new ParsingState()); + Enrich(info, StateWithMaterial()); const int descriptionId = -1010103; var wallDescription = Assert.Single(wall.Parameters, parameter => parameter.Id == descriptionId); @@ -124,7 +132,7 @@ public void TypeReferencesKeepPriorityAndOnlyLevelSelectionExcludesSelf() public void NewThermalFallbackRetainsLegacyValueButIsNotExact(int id, object expected, StorageType storage) { var (info, wall) = Model(); - Enrich(info, new ParsingState()); + Enrich(info, StateWithMaterial()); var parameter = Assert.Single(wall.Parameters, p => p.Id == id); Assert.Equal(expected, parameter.Value); Assert.Equal(storage, parameter.StorageType); @@ -132,7 +140,7 @@ public void NewThermalFallbackRetainsLegacyValueButIsNotExact(int id, object exp Assert.Null(parameter.SpecType); Assert.Null(parameter.ConversionFactor); string serialized = JsonSerializer.Serialize(parameter); - Enrich(info, new ParsingState()); + Enrich(info, StateWithMaterial()); Assert.Same(parameter, Assert.Single(wall.Parameters, p => p.Id == id)); Assert.Equal(serialized, JsonSerializer.Serialize(parameter)); Assert.True(parameter.IsApproximate); @@ -152,7 +160,7 @@ public void ExistingParameterIsNeverReplacedOrRemarked(int id, object? value, bo SpecType = "own-spec", UnitSymbol = "own-unit", ConversionFactor = 2.5 }; wall.Parameters.Add(parameter); string before = JsonSerializer.Serialize(parameter); - Enrich(info, new ParsingState()); + Enrich(info, StateWithMaterial()); Assert.Same(parameter, Assert.Single(wall.Parameters, p => p.Id == id)); Assert.Equal(before, JsonSerializer.Serialize(parameter)); Assert.Equal(approximate, parameter.IsApproximate); @@ -180,7 +188,7 @@ public void ExistingFallbackScopeIsNotExpanded(string mutation) case "unresolved_material": wall.References = [21]; break; case "wrong_material_category": info.Elements[1].CategoryId = -2000023; break; } - Enrich(info, mutation == "null_state" ? null : new ParsingState()); + Enrich(info, mutation == "null_state" ? null : StateWithMaterial()); Assert.DoesNotContain(wall.Parameters, p => ThermalIds.Contains(p.Id)); } @@ -192,7 +200,7 @@ public void ResistanceStillRequiresExistingDoubleWidth(object? width, StorageTyp var (info, wall) = Model(); wall.Parameters[0].Value = width; wall.Parameters[0].StorageType = storage; - Enrich(info, new ParsingState()); + Enrich(info, StateWithMaterial()); Assert.DoesNotContain(wall.Parameters, p => p.Id == -1005431); Assert.All(wall.Parameters.Where(p => ThermalIds.Contains(p.Id)), p => Assert.True(p.IsApproximate)); } From d4f3d9eea38a8b898626e5c46f65815f645c4bf7 Mon Sep 17 00:00:00 2001 From: mie <79989386+mahach666@users.noreply.github.com> Date: Wed, 2 Dec 2026 16:01:27 +0300 Subject: [PATCH 3/4] Keep the names of a private fixture out of a test comment --- tests/RvtIO.Tests/ApiTests.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/RvtIO.Tests/ApiTests.cs b/tests/RvtIO.Tests/ApiTests.cs index 861b06da..8afafbc2 100644 --- a/tests/RvtIO.Tests/ApiTests.cs +++ b/tests/RvtIO.Tests/ApiTests.cs @@ -1095,10 +1095,8 @@ public void InvestigateNameStoragePattern() public void SearchBetonString() { // both counts include id 172544, a load case by its header that Revit does not return as an element; a graphic - // style and a category element have no name of their own here and are in neither: four category elements carried - // the name "Бетонный блок" of a neighbour, and two elements the name "900 x 300 мм" that they took through a link to one; - // a material keeps its own name, which it used to lose to the name of the element that its type link guessed - // ("Бетон - Железобетон" was "Бетон", "Бревна диаметром - 300мм" was a name without 300) + // style and a category element have no name of their own here and are in neither, and a material keeps its own + // name instead of the name of the element that its type link guessed Assert.Equal(38, _doc.Elements.Count(e => e.Name != null && e.Name.Contains("Бетон"))); Assert.Equal(48, _doc.Elements.Count(e => e.Name != null && e.Name.Contains("300"))); var material = _doc.GetElement(100935)!; From fb4f9f87d509f168120782aafe1ad00e3f7d1531 Mon Sep 17 00:00:00 2001 From: mahach666 <79989386+mahach666@users.noreply.github.com> Date: Fri, 4 Dec 2026 03:48:04 +0300 Subject: [PATCH 4/4] Require a native fill pattern record for wall fill patterns --- src/RvtIO/Parsing/ElementBuilder.cs | 14 ++++++-------- tests/RvtIO.Tests/NoTypeElementLinkTests.cs | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/RvtIO/Parsing/ElementBuilder.cs b/src/RvtIO/Parsing/ElementBuilder.cs index ce52ce15..bc348960 100644 --- a/src/RvtIO/Parsing/ElementBuilder.cs +++ b/src/RvtIO/Parsing/ElementBuilder.cs @@ -8247,20 +8247,18 @@ void Accumulate(ref RefScan scan, int rid, int ownerId, bool isWall) if (state.ElemClassIdx.GetValueOrDefault((uint)rid) == 2486) scan.MaterialId ??= rid; break; case -2009014: scan.CoverTypeId ??= rid; break; // OST_CoverType - case -2000081: scan.FillPatternId ??= rid; break; // OST_FillPatterns case -2000240: // OST_Levels - first is base, second is top if (scan.FirstLevelId == -1) scan.FirstLevelId = rid; else if (scan.SecondLevelId == null && rid != scan.FirstLevelId) scan.SecondLevelId = rid; break; } - // Fallback: detect cover type / fill pattern by Category string when ID doesn't match + // The cover type may be identified by category name alone. if (scan.CoverTypeId == null && refElem.Category == "OST_CoverType") scan.CoverTypeId = rid; - if (scan.FillPatternId == null && refElem.Category == "OST_FillPatterns") scan.FillPatternId = rid; - // Fill pattern often has no category in our output but its name is the pattern name - // (for example concrete or hatch names) - accept refs in the right ID range as candidates, - // when the file stores them as fill pattern elements (class 1851). - if (scan.FillPatternId == null && refElem.Category == null && rid > 100 && rid < 10000 - && !string.IsNullOrEmpty(refElem.Name) && isWall + // A category can be inherited. Require the FillPatternElem record even when the category matches. + // Named fill patterns without a category can still be used for walls within the existing ID range. + if (scan.FillPatternId == null + && (category == -2000081 || refElem.Category == "OST_FillPatterns" + || (refElem.Category == null && isWall && rid > 100 && rid < 10000 && !string.IsNullOrEmpty(refElem.Name))) && state.ElemClassIdx.GetValueOrDefault((uint)rid) == 1851) scan.FillPatternId = rid; } diff --git a/tests/RvtIO.Tests/NoTypeElementLinkTests.cs b/tests/RvtIO.Tests/NoTypeElementLinkTests.cs index 92415672..d1822bc2 100644 --- a/tests/RvtIO.Tests/NoTypeElementLinkTests.cs +++ b/tests/RvtIO.Tests/NoTypeElementLinkTests.cs @@ -314,23 +314,32 @@ public void EnrichTypeLevelBips_TakesAsMaterialOnlyAMaterialElement() Assert.Equal(21, withMaterial.Parameters.Single(parameter => parameter.Id == -1005500).Value); } - [Fact] - public void EnrichTypeLevelBips_TakesAsFillPatternOnlyAFillPatternElement() + [Theory] + [InlineData(false)] + [InlineData(true)] + public void EnrichTypeLevelBips_TakesAsFillPatternOnlyAFillPatternElement(bool categorized) { // named elements without a category in the id range of the old guess: a dimension style and a parameter element var dimensionStyle = new Element { Id = 277, TypeId = -1, Name = "Arrow 1" }; var parameterElement = new Element { Id = 3000, TypeId = -1, Name = "Floor number" }; var fillPattern = new Element { Id = 442, TypeId = -1, Name = "Concrete" }; + var category = WithCategory(new Element { Id = 443, TypeId = -1 }, -2000081, "OST_FillPatterns"); + var style = new Element { Id = 444, TypeId = -1, Category = "OST_FillPatterns" }; + if (categorized) WithCategory(fillPattern, -2000081, "OST_FillPatterns"); var onlyOthers = WithCategory(new Element { Id = 50, TypeId = -1, References = [277, 3000] }, WallsCategory, "OST_Walls"); - var withFillPattern = WithCategory(new Element { Id = 51, TypeId = -1, References = [277, 3000, 442] }, WallsCategory, "OST_Walls"); - var elements = new[] { dimensionStyle, parameterElement, fillPattern, onlyOthers, withFillPattern }; + var onlyCategory = WithCategory(new Element { Id = 51, TypeId = -1, References = [443] }, WallsCategory, "OST_Walls"); + var onlyStyle = WithCategory(new Element { Id = 52, TypeId = -1, References = [444] }, WallsCategory, "OST_Walls"); + var withFillPattern = WithCategory(new Element { Id = 53, TypeId = -1, References = [443, 444, 442] }, WallsCategory, "OST_Walls"); + var elements = new[] { dimensionStyle, parameterElement, fillPattern, category, style, onlyOthers, onlyCategory, onlyStyle, withFillPattern }; var info = new RevitFileInfo(); info.Elements.AddRange(elements); - var state = StateOf((277, 174), (3000, 2873), (442, FillPatternClass)); + var state = StateOf((277, 174), (3000, 2873), (442, FillPatternClass), (443, CategoryElementClass), (444, GraphicStyleClass)); ElementBuilder.EnrichTypeLevelBips(info, state, elements.ToDictionary(element => element.Id)); Assert.DoesNotContain(onlyOthers.Parameters, parameter => parameter.Id == -1002106); + Assert.DoesNotContain(onlyCategory.Parameters, parameter => parameter.Id == -1002106); + Assert.DoesNotContain(onlyStyle.Parameters, parameter => parameter.Id == -1002106); Assert.Equal(442, withFillPattern.Parameters.Single(parameter => parameter.Id == -1002106).Value); }