浏览代码

mxg:添加批量删除Zero空间

mengxiangge 6 年之前
父节点
当前提交
519d7a201e
共有 3 个文件被更改,包括 110 次插入15 次删除
  1. 1 0
      MBI/SAGA.MBI/SAGA.MBI.csproj
  2. 13 15
      MBI/SAGA.MBI/ToolCommand.cs
  3. 96 0
      MBI/SAGA.MBI/ToolsData/DelZeroSpace.cs

+ 1 - 0
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -274,6 +274,7 @@
     <Compile Include="RequestData\QRCodeRequest.cs" />
     <Compile Include="RevitModelHandle\RevitParameterUpdate.cs" />
     <Compile Include="RevitReference\RVTNoModeDutyOperate.cs" />
+    <Compile Include="ToolsData\DelZeroSpace.cs" />
     <Compile Include="ToolsData\CheckBase\CheckOperation.cs" />
     <Compile Include="ToolsData\CheckBase\CheckType.cs" />
     <Compile Include="ToolsData\CheckBase\ICheckBase.cs" />

+ 13 - 15
MBI/SAGA.MBI/ToolCommand.cs

@@ -44,23 +44,21 @@ namespace SAGA.MBI
         {
             try
             {
-                var doc = ExternalDataWrapper.Current.Doc;
-                using (Transaction trans = new Transaction(doc, "删除"))
+                int count = 0;
+                var tip = MessageShowBase.Question2("确定要删除所有楼层周长为零的空间?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
+                switch (tip)
                 {
-                    trans.Start();
-                    try
-                    {
-                        var spaces = doc.GetSpaces().Where(t => t.IsDeleteSpace());
-                        doc.Delete(spaces.Select(t => t.Id).ToList());
-                        trans.Commit();
-                        MessageShowBase.Infomation("删除成功");
-                    }
-                    catch (Exception)
-                    {
-                        trans.RollBack();
-
-                    }
+                    case DialogResult.Yes:
+                        count=DelZeroSpace.OperateAll();
+                        break;
+                    case DialogResult.No:
+                        count=DelZeroSpace.OperateCurFloor();
+                        break;
+                    default:
+                        break;
                 }
+                if(tip== DialogResult.Yes||tip== DialogResult.No)
+                    MessageShowBase.Infomation($"此次操作共删除{count}个空间");
 
             }
             catch (Exception e)

+ 96 - 0
MBI/SAGA.MBI/ToolsData/DelZeroSpace.cs

@@ -0,0 +1,96 @@
+/* ==============================================================================
+ * 功能描述:删除周长为零的空间
+ * 创 建 者:Garrett
+ * 创建日期:2018/7/12 14:25:17
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.DotNetUtils.Others;
+using SAGA.MBI.Calc;
+using SAGA.MBI.Model;
+using SAGA.MBI.RequestData;
+using SAGA.MBI.WinView.Upload;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Mechanical;
+using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Logger;
+using SAGA.MBI.DataArrange;
+using SAGA.MBI.Tools;
+using SAGA.RevitUtils.Extends;
+
+namespace SAGA.MBI.ToolsData
+{
+    /// <summary>
+    /// CheckEquipCategory
+    /// </summary>
+    public class DelZeroSpace
+    {
+        /// <summary>
+        /// 检查并处理所有楼层
+        /// </summary>
+        public static int OperateAll()
+        {
+            int count = 0;
+            var floors = DalUploadFloor.GetHasFileFloors();
+            foreach (UploadFloor floor in floors)
+            {
+                count+=Operate(floor.MFloor);
+            }
+            return count;
+        }
+        /// <summary>
+        /// 只处理当前楼层
+        /// </summary>
+        public static int OperateCurFloor()
+        {
+            int count = 0;
+            MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor();
+            if (floor != null)
+                count=Operate(floor);
+            return count;
+        }
+        /// <summary>
+        /// 检查并处理
+        /// </summary>
+        /// <param name="floor"></param>
+        /// <returns></returns>
+        private static int Operate(MFloor floor)
+        {
+            int count = 0;
+            var context = DalCommon.DownLoadCouldData(floor);
+            context.OpenDocument();
+            try
+            {
+                var doc = context.RevitDoc;
+                using (Transaction trans = new Transaction(doc, "删除"))
+                {
+                    trans.Start();
+                    try
+                    {
+                        var spaces = doc.GetSpaces().Where(t => t.IsDeleteSpace()).ToList();
+                        count = spaces.Count;
+                        doc.Delete(spaces.Select(t => t.Id).ToList());
+                        trans.Commit();
+                    }
+                    catch (Exception)
+                    {
+                        trans.RollBack();
+
+                    }
+                }
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+            finally
+            {
+                context.RevitDoc.CloseDoc();
+            }
+            return count;
+        }
+    }
+}