0

I am using the following C# code to access geometry data from an ifc4 file. The file contains only a wall created using Revit 2016. I am using Xbim library. This is my code:

class Program
{
    private static readonly ILog logger =
       LogManager.GetLogger(typeof(Program));
    static string _ifcFile = @"C:\Examples\OneWall.ifc";

    static void Main(string[] args)
    {
        BasicConfigurator.Configure();

        IfcStore model = IfcStore.Open(_ifcFile);
        Xbim3DModelContext context = new Xbim3DModelContext(model);
        context.CreateContext();
        XbimMeshGeometry3D mesh = mesh = (XbimMeshGeometry3D)context.ShapeGeometryMeshOf(context.ShapeInstances().FirstOrDefault());

        //The rest of my code
    }
} 

I get the following error. I am using visual studio 2015.

1226 [1] DEBUG Xbim.Geometry.Engine.Interop.XbimCustomAssemblyResolver (null) - Loading assembly from: C:\Examples\ifcWall\ifcWall\bin\Debug\x86\Xbim.Geometry.Engine32.dll 1404 [1] DEBUG Xbim.Geometry.Engine.Interop.XbimCustomAssemblyResolver (null) - Loading assembly from: C:\Examples\ifcWall\ifcWall\bin\Debug\x86\Xbim.Geometry.Engine32.dll

Unhandled Exception: System.Exception: Invalid Geometry Command at Xbim.ModelGeometry.Scene.XbimMeshGeometry3D.Read(String data, Nullable1 trans) in c:\BuildAgent\work\860c3b913b6c647f\Xbim.ModelGeometry.Scene\XbimMeshGeometry3D.cs:line 219 at Xbim.ModelGeometry.Scene.XbimMeshGeometry3D.Add(String mesh, Int16 productTypeId, Int32 productLabel, Int32 geometryLabel, Nullable1 transform, Int16 modelId) in c:\BuildAgent\work\860c3b913b6c647f\Xbim.ModelGeometry.Scene\XbimMeshGeometry3D.cs:line 669 at Xbim.ModelGeometry.Scene.Xbim3DModelContext.ShapeGeometryMeshOf(XbimShapeInstance shapeInstance) in c:\BuildAgent\work\860c3b913b6c647f\Xbim.ModelGeometry.Scene\Xbim3DModelContext.cs:line 1525 at ifcWall.Program.Main(String[] args) in C:\Users\karshenas\Documents\Courses\CEEN6840\VS_Projects\ifcWall\ifcWall\Program.cs:line 26

Any help to fix the error is appreciated.

1 Answers1

0

You run into an area where API has changed and this particular functions expects data in a different format. If what you need is a triangulation of the shape this code should work for you:

using System.IO;
using Xbim.Common.Geometry;
using Xbim.Ifc;
using Xbim.ModelGeometry.Scene;
using Xbim.Common.XbimExtensions;

namespace CreateWexBIM
{
    class Program
    {
        static void Main(string[] args)
        {
            const string file = @"4walls1floorSite.ifc";

            var model = IfcStore.Open(file);
            var context = new Xbim3DModelContext(model);
            context.CreateContext();

            var instances = context.ShapeInstances();
            foreach (var instance in instances)
            {
                var geometry = context.ShapeGeometry(instance);
                var data = ((IXbimShapeGeometryData)geometry).ShapeData;
                using (var stream = new MemoryStream(data))
                {
                    using (var reader = new BinaryReader(stream))
                    {
                        var mesh = reader.ReadShapeTriangulation();
                    }
                }
            }
        }

    }
}

The best is to ask in xBIM GitHub Issues and to share the file. IFC geometry can get very complex so it is not possible to really answer your question just based on the exception.

Martin Cerny
  • 344
  • 3
  • 9