Search code examples
c#ifcxbim

Getting the wall coordinates from IFC file with XBIM


I need to get the list of vertices of IfcWall object using XBIM. The code i need must look something like:

using (model)
{
    List<ItemSet<IfcCartesianPoints>> loppsList = new List<ItemSet<IfcCartesianPoints>>();
    var walls = model.Instances.OfType<IfcWall>();

    foreach (var wall in walls)
    {
        loppsList.Add(wall. ... .Points);
    }
}

But i have no idea, how to get the proper way .

I tried the solution proposed here: IFC objects navigation to retrieve Wall coordinates

foreach (var wall in walls)
{
    var line = wall.Representation.Representations[0].Items[0];
    var _line  = line as IfcPolyline;
    loppsList.Add(_line.Points);
}

But i didn't get the proper data — maybe I just got lost in the path of attributes. Please help to navigate through the IfcWall attributes.


Solution

  • Ok, if someone in future will face the same question, the full way is:

    wall.Representation.Representations[].Items[].Outer[].CfsFaces[].Bounds[].Bound.Polygon[]

    //this is how i print the x coordinates of all points
    using (model)
            {
    
                var walls = model.Instances.OfType<IIfcWall>();
    
                foreach (var wall in walls)
                {
                    var loop = wall.Representation.Representations[1].Items[0];
    
                    if (loop is IfcFacetedBrep)
                    {
    
                        var _loop = loop as IfcFacetedBrep;
                        foreach (var face in _loop.Outer.CfsFaces)
                        {
                            foreach (var bound in face.Bounds)
                            {
                                var _b = bound.Bound as IIfcPolyLoop;
                                foreach (var point in _b.Polygon)
                                {
                                    Debug.WriteLine(point.ToString());
                                }
                            }
                        }
                    }
                }
            }
    

    But:

    1. Representations[] element must be IfcFacetedBrep (if it is IfcBooleanClippingResult, then i have no idea what to do)

    2. Indexes of the Representations[], Items[] and other arrays are unknon

    3. Walls can be as IfcWall (IFC 4), as IIfcWall (IFC 2x3) and the navigation through this objects are different

    Do not use IFC.