如何使用 Xbim 为 IFC 对象创建和操作 Table 属性?

How do I create and manipulate a Table property for an IFC object using Xbim?

我正在处理修改数据的基本示例 (https://github.com/xBimTeam/XbimEssentials)。我唯一要更改的是下面的代码,我想在其中添加 IfcPropertyTableValue 而不是 IfcPropertySingleValue。

此代码运行,但在对象属性下的 XbimXplorer 中,什么也没有 - 它是空白的。

为确保示例代码以及其他 属性 类型确实有效,并且确实显示在 Xplorer 的属性下。

 var pSetRel = model.Instances.New<IfcRelDefinesByProperties>(r =>
                                {
                                    r.GlobalId = Guid.NewGuid();
                                    r.RelatingPropertyDefinition = model.Instances.New<IfcPropertySet>(pSet =>
                                    {
                                        pSet.Name = "Points";

                                        // FOR EACH POINT i :
                                        pSet.HasProperties.Add(model.Instances.New<IfcPropertyTableValue>(p =>
                                        {
                                            
                                            p.Name = "Points " + i;
                                            
                                            // FOR EACH COORDINATE x : 
                                            p.DefiningValues.Add(new IfcText(x));
                                            p.DefinedValues.Add(new IfcReal(-3.25));

                                        }));
                                    });
                                });

我怎样才能使这个工作?

我也尝试过使用代码读取 属性,以防 XbimXplorer 不显示表格。此代码运行并打印零行(但适用于 Xplorer 中显示的其他属性):

// Try to read and print the new property
                    var nameObj = "my_object_name";
                    var checkObj = model.Instances.FirstOrDefault<IIfcBuildingElement>(d => d.Name == nameObj);
                    if (checkObj == null)
                    {
                        outputBox.AppendText(newLine + "Object: " + nameObj + " not found");
                    }
                    else
                    {
                        var properties = checkObj.IsDefinedBy
                            .Where(r => r.RelatingPropertyDefinition is IIfcPropertySet)
                            .SelectMany(r => ((IIfcPropertySet)r.RelatingPropertyDefinition).HasProperties)
                            .OfType<IIfcPropertySingleValue>();
                        foreach (var property in properties)
                            outputBox.AppendText($"Property: {property.Name}, Value: {property.NominalValue}");
                    }

如果我可以一次添加多个 defining/defined 值对,也会很方便,例如像这样(类似于普通的 C# 列表):

IEnumerable<IfcValue> definingValues = new IfcText() {"x", "y", "z", "k"};
p.DefinedValues.AddRange(definingValues);

IEnumerable<IfcValue> definedValues = new IfcReal() {0.0, 1.6, -2.5, 3.33};
p.DefinedValues.AddRange(definedValues);

但是,{"x", "y", "z", "k"} 随后被标记为错误 无法使用集合初始化程序初始化类型 'IfcText',因为它没有实现 'System.Collections.IEnumerable' .

我认为 xbim Xplorer 不显示 IfcPropertyTableValues。可能是因为目前很少有 BIM 工具输出 TableValues,所以我猜它从未实现(并且您需要确定如何在 Xplorer 视图中显示 table - 您是否将 table 嵌套在 属性格子?).

如果您查看 Xplorer code,您会发现它仅支持 SingleValues、ComplexValues 和 EnumeratedValues。作为解决方法,您可以使用复杂值作为多个 IfcPropertySingleValues 的集合。

在您输出值的第二个代码示例中,您使用 .OfType<IIfcPropertySingleValue>() 子句过滤掉所有 IfcPropertyTableValues,因此您将永远看不到输出。查看 SimpleProperties 的 IFC 规范:https://standards.buildingsmart.org/IFC/RELEASE/IFC4_1/FINAL/HTML/link/ifcsimpleproperty.htm

关于最后一个问题,您使用错误的语法初始化数组。尝试这样的事情:

var labels = new Ifc4.MeasureResource.IfcText[] { "x", "y" };
p.DefiningValues.AddRange(labels.Cast<IIfcValue>());