【问题标题】:Xbim Geometry errorXbim 几何错误
【发布时间】:2017-07-02 03:38:32
【问题描述】:

我正在使用以下 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] 调试 Xbim.Geometry.Engine.Interop.XbimCustomAssemblyResolver (null) - 从以下位置加载程序集:C:\Examples\ifcWall\ifcWall\bin\Debug\x86\Xbim.Geometry.Engine32.dll 1404 [1] 调试 Xbim.Geometry.Engine.Interop.XbimCustomAssemblyResolver (null) - 从 C:\Examples\ifcWall\ifcWall\bin\Debug\x86\Xbim.Geometry.Engine32.dll 加载程序集

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

感谢任何帮助修复错误。

【问题讨论】:

    标签: c# geometry ifc xbim


    【解决方案1】:

    您遇到了 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 几何结构可能会变得非常复杂,因此仅根据例外情况无法真正回答您的问题。

    【讨论】:

    • 请仅使用发布答案按钮获取实际答案。拥有enough rep 后,您就可以将 cmets 添加到问题中。
    • 编辑答案以提供实际解决方案。
    猜你喜欢
    • 2017-08-05
    • 1970-01-01
    • 2014-11-09
    • 2021-01-28
    • 2020-09-13
    • 2014-12-23
    • 2019-04-22
    • 1970-01-01
    • 2022-08-14
    相关资源
    最近更新 更多