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的坐标,但是运行以上代码时系统崩了
PolyfaceVisitor需要在using语句中使用,如下所示:
using (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); } }
MS学习资源:
MicroStation Wednesday视频分享
深入探讨MicroStation DGN基本概念系列
一步步学习MicroStation CE Addin开发
一步步学习MicroStation CE MDL开发
Answer Verified By: micro wish