private void tb_Calculation_Click(object sender, RoutedEventArgs e) { // 需要传入的参数 double volume, area, closureError, ixy, ixz, iyz; BG.DPoint3d centroid, moment, principalMoment, pricipalDirection; IntPtr nativeEdp; BD.DgnModel activeModel = Program.GetActiveDgnModel(); double uor_per_meter = activeModel.GetModelInfo().UorPerMeter; IntPtr modelPtr = activeModel.GetNative(); BD.LevelCache levelCache = activeModel.GetLevelCache(); //存储每层图层对应的工程量 Dictionary <string, double> volumeByLevel = new Dictionary <string, double>(); string eleLevelName; foreach (var ele in activeModel.GetGraphicElements()) { if (0 != BentleyMarshal.mdlElmdscr_getByElemRef(out nativeEdp, ele.GetNativeElementRef(), modelPtr, 0, IntPtr.Zero)) { if (0 == BentleyMarshal.mdlMeasure_volumeProperties(out volume, out area, out closureError, out centroid, out moment, out ixy, out ixz, out iyz, out principalMoment, out pricipalDirection, nativeEdp, uor_per_meter / 10000)) { eleLevelName = levelCache.GetLevel(ele.LevelId).Name; if (!volumeByLevel.ContainsKey(eleLevelName)) { volumeByLevel.Add(eleLevelName, 0); } volumeByLevel[eleLevelName] += volume / Math.Pow(uor_per_meter, 3); } } //利用DoEvents强制循环队列,防止界面卡死 Bentley.UI.Threading.DispatcherHelper.DoEvents(); } foreach (var i in volumeByLevel) { result.Add(new QuantitiesByLevelResult() { LevelName = i.Key, Quantities = Math.Round(i.Value, 2) }); } lv_output.ItemsSource = result; }
public static void TestGetVolum() { double volume, area, closureError, ixy, ixz, iyz; Bentley.GeometryNET.DPoint3d centroid, moment, principalMoment, pricipalDirection; BD.DgnModel activemodel = Program.GetActiveDgnModel(); double uor_per_master = activemodel.GetModelInfo().UorPerMaster; foreach (var item in activemodel.GetGraphicElements()) { IntPtr nativeElePtr = item.GetNativeElementRef(); IntPtr nativeEdp; IntPtr filePos = IntPtr.Zero; if (nativeElePtr != null) { Marshal.BentleyMarshal.mdlElmdscr_getByElemRef(out nativeEdp, nativeElePtr, activemodel.GetNative(), 0, filePos); if (0 == Marshal.BentleyMarshal.mdlMeasure_volumeProperties(out volume, out area, out closureError, out centroid, out moment, out ixy, out ixz, out iyz, out principalMoment, out pricipalDirection, nativeEdp, uor_per_master / 10)) { BD.NotificationManager.OutputMessage(new BD.NotifyMessageDetails(Bentley.DgnPlatformNET.OutputMessagePriority.Information, volume.ToString(), volume.ToString(), BD.NotifyTextAttributes.DynamicScroll, BD.OutputMessageAlert.None)); } } } }