Skip to content

Commit a89407a

Browse files
authored
Ignore null properties and empty psets (#668)
1 parent a3285a4 commit a89407a

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Importers/Ifc/Speckle.Importers.Ifc.Tester2/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
using Speckle.Sdk.Models;
1111

1212
// Settings
13-
// var filePath = new FilePath(@"C:\Users\Jedd\Desktop\GRAPHISOFT_Archicad_Sample_Project-S-Office_v1.0_AC25.ifc");
14-
var filePath = new FilePath(@"C:\Users\Jedd\Desktop\BIM_Projekt_Golden_Nugget-Architektur_und_Ingenieurbau.ifc");
13+
var filePath = new FilePath(@"C:\Users\Jedd\Desktop\KLY-ZHQ-B-CPL1_CPL4-0-ELV-SD-210.ifc");
14+
15+
// var filePath = new FilePath(@"C:\Users\Jedd\Desktop\BIM_Projekt_Golden_Nugget-Architektur_und_Ingenieurbau.ifc");
1516
const string PROJECT_ID = "f3a42bdf24";
1617

1718
// Setup

Importers/Ifc/Speckle.Importers.Ifc/Converters/NodeExtensions.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public static class NodeExtensions
1010
var result = new Dictionary<string, object?>();
1111
foreach (var p in node.GetPropSets())
1212
{
13-
if (p.NumProperties <= 0)
14-
continue;
15-
1613
var name = p.Name;
1714
if (string.IsNullOrWhiteSpace(name))
1815
name = $"#{p.Id}";
19-
result[name] = ToSpeckleDictionary(p);
16+
17+
var dict = ToSpeckleDictionary(p);
18+
if (dict.Count > 0) //Ignore any empty psets, since they can bloat the data size
19+
result[name] = dict;
2020
}
2121

2222
return result;
@@ -26,7 +26,16 @@ public static class NodeExtensions
2626
{
2727
var d = new Dictionary<string, object?>();
2828
foreach (var p in ps.GetProperties())
29-
d[p.Name] = p.Value.ToJsonObject();
29+
{
30+
var value = p.Value.ToJsonObject();
31+
32+
if (value is not null)
33+
{
34+
// Ignoring null values since they'd otherwise bloat the data size of speckle models.
35+
// Semantically, "null valued" and "not there" are different, but very few users care about the distinction.
36+
d[p.Name] = value;
37+
}
38+
}
3039
return d;
3140
}
3241
}

0 commit comments

Comments
 (0)