xBimTeam / XbimWindowsUI

The home of XbimXplorer and WPF components for your desktop BIM applications.
Other
252 stars 149 forks source link

How to add a new IIfcRelContainedInSpatialStructure relationship in a ifc file. #165

Closed Ferbeas closed 3 years ago

Ferbeas commented 3 years ago

Hello,

I want to create the relationship between an IfcSpace and an IfcBuidingElementProxy. According to this the IfcSpace connects with an IfcProduct through the IIfcRelContainedInSpatialStructure relationship.

using (var model = IfcStore.Open(sample))
            {
                var theElement = model.Instances.FirstOrDefault<IIfcBuildingElementProxy>();
                var theSpace = model.Instances.FirstOrDefault<IIfcSpace>();
                //open transaction for changes
                using (var txn = model.BeginTransaction("AddRelationship"))
                {

                    var rel = model.Instances.New<IIfcRelContainedInSpatialStructure>(r =>
                    {

                        r.GlobalId = Guid.NewGuid();
                        r.RelatedElements.Add(theElement);
                        r.RelatingStructure = theSpace;
                    });
                    txn.Commit();
                }
                model.SaveAs("sample2.ifc");
            }

This is the error it gives image

How to properly use the IIfcRelContainedInSpatialStructure relationship?

andyward commented 3 years ago

When you create a new instance of a model entity it needs to be a class not an interface. IIfcRelContainedInSpatialStructure is an interface. Take the initial 'I' off and import the correct namespace (depending on whether you want IFC2x3 or Ifc4)

Ferbeas commented 3 years ago

Thanks @andyward, problem solved.