XbimEssentials icon indicating copy to clipboard operation
XbimEssentials copied to clipboard

Getting sub components of site

Open SunilApte opened this issue 1 year ago • 3 comments

We are currently replacing HOOPS with Xbim. In HOOPS we have following code:

HPS.Component[] children = m_compIFCSites.GetSubcomponents();
                        foreach (Component compsurface in children.ToList())
                        {
                            var type = ComponentPropertyBuilder.FindStringPropertyTypecheck(compsurface);
                            if (type != "IFCBUILDING"/* && compsurface.GetName().ToLower().Contains("surface")*/)//Identity Data/Mark	Plot

                            {

I can get IfcSite using xbim. But how can I get sub components? I can get buildings and spaces from ifcsite. But I need all sub components under site whose type is not building.

How to achieve this?

SunilApte avatar May 28 '24 14:05 SunilApte

When you say subcomponents, do you mean the geometrical parts (often terrain surface in case of IfcSite), or do you mean semantic breakdown (building(s), level(s), space(s))?

martin1cerny avatar May 29 '24 10:05 martin1cerny

Subcomponents in case of HOOPS is breakdown like buildings and other subcomponents of different Ifc elements. In case of xbim how to achieve above?

SunilApte avatar May 29 '24 14:05 SunilApte

You just need to iterate through the aggregation relation recursively.

private static void ExploreDecomposition(IIfcObjectDefinition entity, string indent)
{
    Console.WriteLine(indent + entity.Name);
    var children = entity.IsDecomposedBy.SelectMany(r => r.RelatedObjects);

    indent += "    ";
    foreach (var child in children)
    {
        ExploreDecomposition(child, indent);
    }
}

var site = model.Instances.FirstOrDefault<IIfcSite>();
ExploreDecomposition(site);

Note: Code is subject to optimisation and refactoring before used in production.

martin1cerny avatar May 30 '24 07:05 martin1cerny