Xbim几何错误

时间:2017-02-14 00:58:46

标签: c# geometry ifc xbim

我使用以下C#代码从ifc4文件访问几何数据。该文件仅包含使用Revit 2016创建的墙。我使用的是Xbim库。这是我的代码:

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
    }
} 

我收到以下错误。我正在使用visual studio 2015。

1226 [1] DEBUG Xbim.Geometry.Engine.Interop.XbimCustomAssemblyResolver(null) - 从以下位置加载程序集:C:\ Examples \ ifcWall \ ifcWall \ bin \ Debug \ x86 \ Xbim.Geometry.Engine32.dll 1404 [1] DEBUG Xbim.Geometry.Engine.Interop.XbimCustomAssemblyResolver(null) - 从以下位置加载程序集:C:\ Examples \ ifcWall \ ifcWall \ bin \ Debug \ x86 \ Xbim.Geometry.Engine32.dll

未处理的异常:System.Exception:无效的几何命令    at Xbim.ModelGeometry.Scene.XbimMeshGeometry3D.Read(String data,Nullable 1 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, Nullable 1 transform,Int16 modelId)in c:\ BuildAgent \ work \ 860c3b913b6c647f \ Xbim.ModelGeometry.Scene \ XbimMeshGeometry3D.cs:line 669    位于c:\ BuildAgent \ work \ 860c3b913b6c647f \ Xbim.ModelGeometry.Scene \ Xbim3DModelContext.cs中的Xbim.ModelGeometry.Scene.Xbim3DModelContext.ShapeGeometryMeshOf(XbimShapeInstance shapeInstance):第1525行    at ifcWall.Program.Main(String [] args)在C:\ Users \ karshenas \ Documents \ Courses \ CEEN6840 \ VS_Projects \ ifcWall \ ifcWall \ Program.cs:第26行

我们非常感谢您解决错误的任何帮助。

1 个答案:

答案 0 :(得分:0)

您遇到API已更改的区域,此特定功能需要使用不同格式的数据。如果你需要的是形状的三角测量,这个代码应该适合你:

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();
                    }
                }
            }
        }

    }
}

最好是在xBIM GitHub Issues询问并分享文件。 IFC几何可能变得非常复杂,因此不可能仅基于异常来回答您的问题。