Skip to content

IFC hierarchy retrieveal - get elements under IfcSpace #76

@ani-rudh

Description

@ani-rudh

@martin1cerny , thanks for the right pointer to hierarchy decomposition through this code in issue #73

using System;
using System.Linq;
using Xbim.Ifc;
using Xbim.Ifc4.Interfaces;

namespace BasicExamples
{
    class SpatialStructureExample
    {
        public static void Show()
        {
            const string file = "SampleHouse.ifc";
            
            using (var model = IfcStore.Open(file))
            {
                var project = model.Instances.FirstOrDefault<IIfcProject>();
                PrintHierarchy(project, 0);
            }
        }

        private static void PrintHierarchy(IIfcObjectDefinition o, int level)
        {
            Console.WriteLine($"{GetIndent(level)}{o.Name} [{o.GetType().Name}]");
            foreach (var item in o.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
                PrintHierarchy(item, level +1);
        }

        private static string GetIndent(int level)
        {
            var indent = "";
            for (int i = 0; i < level; i++)
                indent += "  ";
            return indent;
        }
    }
}

Anyway, this does not return the elements under the IfcSpace object.

For e.g, as attached pictures show, the code retireves the ifcSpace object, but it doesn"t get the ifcAirFlowTerminal that resides under that.

I tried on another code to get IfcSpatialStructureElement.getcontaineditems(), which retrieves the elements.

Is there a way to do the same so that your example can retrieve the deeper levels of the tree structure?

You can consider me a noob if iI am missing something very simple/obvious! I need help, please!

Best,
Ani

1
capture

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions