简体   繁体   中英

xBim ifc manipulation: Trying to add a property set

I'm trying to manipulate an ifc2x3 file with xBim. It's based on the example: https://docs.xbim.net/examples/basic-model-operations.html

But when it comes to var pSetRel = model.Instances.New<IfcRelDefinesByProperties> , it crashes with System.Exception: "This factory only creates types from its assembly" Here is the code:

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");
}

what I'm doing wrong?

You haven't included the using statements, but I would guess that you're referencing the Ifc4 version of IfcRelDefinesByProperties rather than the Ifc2x3 equivalent.

You can't mix & match the schema entities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM