xBimTeam / XbimExchange

XbimExchange contains several COBie schemas and serialisation functions as well as the Model Validation library adopted by theNBS digital toolkit.
https://xbimteam.github.io/
Other
46 stars 42 forks source link

How to get all properties of a IFC Object ( Including Single value and multiple values) ? #74

Open Miralay1983 opened 1 year ago

Miralay1983 commented 1 year ago

Hi there i am noob both C# and Xbim also. I am trying to get a values of some IFC objects and write it to a txt file.

I can get single values but i cant figure out how to get multiple values.

Here is my ugly code :)

using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Xbim; using Xbim.Ifc; using Xbim.Ifc4.Interfaces; using ControlzEx.Standard;

namespace IFCMetadata { class Program { static void Main(string[] args) { const string fileName = @"D:\Mini.ifc";

        using (var model = IfcStore.Open(fileName))
        {

            //get all doors in the model (using IFC4 interface of IfcDoor this will work both for IFC2x3 and IFC4)
            var AllBeams = model.Instances.OfType<IIfcBeam>();
            var AllColumns = model.Instances.OfType<IIfcColumn>();
            var AllWelds = model.Instances.OfType<IIfcFastener>();
            var ALLBolts = model.Instances.OfType<IIfcMechanicalFastener>();
            List<string> Yazi = new List<string>();

            foreach (var item in AllBeams)
            {
                var properties = item.IsDefinedBy
                       .Where(r => r.RelatingPropertyDefinition is IIfcPropertySet)
                   .SelectMany(r => ((IIfcPropertySet)r.RelatingPropertyDefinition).HasProperties)
                    .OfType<IIfcPropertySingleValue>();
                if (Yazi.Count>0)
                {
                     Yazi.Add("$");
                }

                foreach (var property in properties)
                {

                  //  Console.WriteLine(property.Name + property.NominalValue);
                     Yazi.Add(property.Name +":"+  property.NominalValue);
                    // Yazi.Add($"Property: {property.Name}, Value: {property.NominalValue}");

                }

            }

            foreach (var item in AllColumns)
            {
                var properties = item.IsDefinedBy
                       .Where(r => r.RelatingPropertyDefinition is IIfcPropertySet)
                   .SelectMany(r => ((IIfcPropertySet)r.RelatingPropertyDefinition).HasProperties)
                    .OfType<IIfcPropertySingleValue>();
                if (Yazi.Count > 0)
                {
                    Yazi.Add("$");
                }

                foreach (var property in properties)
                {

                    //  Console.WriteLine(property.Name + property.NominalValue);
                    Yazi.Add(property.Name + ":" + property.NominalValue);
                    // Yazi.Add($"Property: {property.Name}, Value: {property.NominalValue}");

                }

            }
            foreach (var item in AllWelds)
            {
                var properties = item.IsDefinedBy
                       .Where(r => r.RelatingPropertyDefinition is IIfcPropertySet)
                   .SelectMany(r => ((IIfcPropertySet)r.RelatingPropertyDefinition).HasProperties)
                    .OfType<IIfcPropertySingleValue>();
                if (Yazi.Count > 0)
                {
                    Yazi.Add("$");
                }

                foreach (var property in properties)
                {

                    //  Console.WriteLine(property.Name + property.NominalValue);
                    Yazi.Add(property.Name + ":" + property.NominalValue);
                    // Yazi.Add($"Property: {property.Name}, Value: {property.NominalValue}");

                }

            }
            foreach (var item in ALLBolts)
            {
                var properties = item.IsDefinedBy
                       .Where(r => r.RelatingPropertyDefinition is IIfcPropertySet)
                   .SelectMany(r => ((IIfcPropertySet)r.RelatingPropertyDefinition).HasProperties)
                    .OfType<IIfcPropertySingleValue>();
                if (Yazi.Count > 0)
                {
                    Yazi.Add("$");
                }

                foreach (var property in properties)
                {

                    //  Console.WriteLine(property.Name + property.NominalValue);
                    Yazi.Add(property.Name + ":" + property.NominalValue);
                    // Yazi.Add($"Property: {property.Name}, Value: {property.NominalValue}");

                }

            }

            var yaziliste = Yazi.ToArray();

            File.WriteAllLines(@"d:\Mini.txt", yaziliste);

        }

    }
}

}