[c# ORD]“System.AccessViolationException”类型的未经处理的异常在 Bentley.GeometryNET.dll 中发生 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

public static void Init()
        {
            ScanCriteria sc = new ScanCriteria();
            sc.SetModelRef(Session.Instance.GetActiveDgnModel());
            sc.SetModelSections(DgnModelSections.GraphicElements);
            sc.SetDrawnElements();
            DgnModelRef dgnModelRef = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModelRef();
            List<Element> elmtsList = new List<Element>();
            
            ScanDelegate scanDelegate = (Element elmt, DgnModelRef modelRef) =>
            {
                elmtsList.Add(elmt);
                return StatusInt.Success;
            };
            sc.Scan(scanDelegate);
            
            foreach (Element element in elmtsList)
            {
                try
                {
                    if (element is MeshHeaderElement)
                    {
                        MeshHeaderElement meshElem = element as MeshHeaderElement;
                        PolyfaceHeader pfh = meshElem.GetMeshData();
                        PolyfaceVisitor pv = new PolyfaceVisitor(pfh, true);
                        while (pv.AdvanceToNextFace())
                        {
                            IEnumerator<DPoint3d> pts = pv.Point.GetEnumerator();
                            while (pts.MoveNext())
                            {
                                DPoint3d pt = pts.Current;
                                string content = pt.X.ToString() + "  " + pt.Y.ToString() + "  " + pt.Z.ToString();
                            }
                            //MessageCenter.Instance.ShowInfoMessage(pt.ToString(), null, false);
                        }

                    }
                }catch(Exception e)
                {
                    MessageBox.Show(e.Message);

                }
                
               
            }
        }
               
    }

我想通过扫描图纸来获取mesh的坐标,但是运行以上代码时系统崩了

Parents Reply Children
No Data