GeometryGym / GeometryGymIFC

C# classes to generate and parse OpenBIM IFC files
Other
269 stars 97 forks source link

Parse Geometry #13

Open jeromerolland opened 5 years ago

jeromerolland commented 5 years ago

Hi, do you have an example for parsing geometry in ifc file ?

best regards, Jérôme

jmirtsch commented 5 years ago

Bonjour Jerome,

If you use the Work In Progress branch of the toolkit, then hoepfully below gives some insights into how to traverse the geometry.

Cheers,

Jon

        DatabaseIfc db = new DatabaseIfc("Filepath");
        List<IfcElement> elements = db.Project.Extract<IfcElement>();
        foreach(IfcElement element in elements)
        {
            foreach (IfcFacetedBrep brep in element.Representation.Representations.SelectMany(x => x.Items).OfType<IfcFacetedBrep>())
            {
                foreach (IfcFace face in brep.Outer.CfsFaces)
                {
                    if(face.Bounds.Count == 1)
                    { 
                        if(face.Bounds[0].Bound is IfcPolyloop polyLoop)
                        {
                            foreach(IfcCartesianPoint p in polyLoop.Polygon)
                            {

                            }
                        }
                    }
                }
            }
        }
jeromerolland commented 5 years ago

Hi Jon,

Thank you very much for your code sample.

Best regards,

Jérôme

CJAndrew84 commented 1 year ago

Jon

Has this code example changed? I'm trying to use it at the moment and it's not liking "Bounds[0].Bound"

Chris

jmirtsch commented 1 year ago

Yes, I've been improving the plugin to use a "SET" (unordered collection) rather than a list when the IFC specification nominates it. You can use linq using "Bounds.First().Bound" instead of a zero index. Sorry for the breaking change, but it does improve the toolkit in other aspects.