首页 > 解决方案 > xBim ifc 操作:尝试添加属性集

问题描述

我正在尝试使用 xBim 操作 ifc2x3 文件。它基于示例:https ://docs.xbim.net/examples/basic-model-operations.html

但是当涉及到时var pSetRel = model.Instances.New<IfcRelDefinesByProperties>,它会崩溃,System.Exception: "This factory only creates types from its assembly" 代码如下:

string fileName = modelsPath + "Duplex_A_20110907.ifc";

using (var model = IfcStore.Open(fileName))
{
    //get existing wall from the model
    var id = "2O2Fr$t4X7Zf8NOew3FNld";
    var wall = model.Instances.FirstOrDefault<IfcWall>(d => d.GlobalId == id);

    //open transaction for changes
    using (var txn = model.BeginTransaction("Walls modification"))
    {
        //create new property set with two properties
        var pSetRel = model.Instances.New<IfcRelDefinesByProperties>(r =>
        {
            r.GlobalId = Guid.NewGuid();
            r.RelatingPropertyDefinition = model.Instances.New<IfcPropertySet>(pSet =>
            {
                pSet.Name = "New property set";
                //all collections are always initialized
                pSet.HasProperties.Add(model.Instances.New<IfcPropertySingleValue>(p =>
                {
                    p.Name = "First property";
                    p.NominalValue = new IfcLabel("First value");
                }));
                pSet.HasProperties.Add(model.Instances.New<IfcPropertySingleValue>(p =>
                {
                    p.Name = "Second property";
                    p.NominalValue = new IfcLengthMeasure(156.5);
                }));
            });
        });

        //change the name of the door
        wall.Name += "_checked";
        //add properties to the door
        pSetRel.RelatedObjects.Add(wall);

        //commit changes
        txn.Commit();
    }

    model.SaveAs(modelsPath + "/Duplex_A_20110907_modified.ifc");
}

我做错了什么?

标签: propertiesifcxbim

解决方案


您没有包含这些using语句,但我猜您引用的是 Ifc4 版本IfcRelDefinesByProperties而不是 Ifc2x3 等效版本。

您不能混合和匹配架构实体。


推荐阅读