Преглед изворни кода

mxg:添加系统导出功能

mengxiangge пре 6 година
родитељ
комит
3e57779b52

+ 14 - 0
MBI/Menu/MBITool.xml

@@ -185,6 +185,20 @@
       <MenuTab>MBITool_W</MenuTab>
       <Modules>MBITool</Modules>
     </Button>
+
+    <Button ButtonStyles="Stacked">
+      <ButtonName>SAGA.MBI.ExportMEPSystemCommand</ButtonName>
+      <ButtonText>导出系统</ButtonText>
+      <ImageName>1、打开楼层模型</ImageName>
+      <DllName>..\OutputDll\SAGA.MBI.exe</DllName>
+      <ClassName>SAGA.MBI.ExportMEPSystemCommand</ClassName>
+      <ToolTip>导出风管系统和水管系统</ToolTip>
+      <LongDescription>导出风管系统和水管系统</LongDescription>
+      <ToolTipImage></ToolTipImage>
+      <MenuTab>MBITool_W</MenuTab>
+      <Modules>MBITool</Modules>
+    </Button>
+    
   </Panel>
  <Panel PanelName="功能扩展" GroupFlag="True" GroupImage="" RevitVer="R14,R15,R16,R17"  ButtonStyles="Large">   
     <Button ButtonStyles="Large">

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

@@ -358,6 +358,7 @@
     <Compile Include="ToolsData\DataCheck\WinDataCheckSetting.xaml.cs">
       <DependentUpon>WinDataCheckSetting.xaml</DependentUpon>
     </Compile>
+    <Compile Include="ToolsData\ExportMEPSystem.cs" />
     <Compile Include="ToolsData\IDataCorrect.cs" />
     <Compile Include="ToolsData\ModeCheck\EquipReferSystemCheck.cs" />
     <Compile Include="ToolsData\ModeCheck\EquipReferSystemCheckResult.cs" />

+ 38 - 0
MBI/SAGA.MBI/ToolCommand.cs

@@ -227,6 +227,44 @@ namespace SAGA.MBI
             return true;
         }
     }
+    /// <summary>
+    /// 导出系统
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class ExportMEPSystemCommand : ExternalCommand
+    {
+        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            try
+            {
+                var tip = MessageShowBase.Question2("确定要导出系统?\r\n是:全部楼层\r\n否:当前楼层\r\n取消:取消。");
+                switch (tip)
+                {
+                    case DialogResult.Yes:
+                        ExportMEPSystem.OperateAll();
+                        break;
+                    case DialogResult.No:
+                        ExportMEPSystem.OperateCurFloor();
+                        break;
+                    default:
+                        break;
+                }
+
+            }
+            catch (Exception e)
+            {
+                MessageShow.Show(e);
+                return Result.Cancelled;
+            }
+            return Result.Succeeded;
+        }
+
+        public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
+        {
+            return true;
+        }
+    }
 
     /// <summary>
     /// 复制指定参数A的值到指定参数B中

+ 3 - 3
MBI/SAGA.MBI/ToolsData/ExportAllDuty.cs

@@ -121,12 +121,12 @@ namespace SAGA.MBI.ToolsData
 
                     ICell cell3 = row.CreateCell(3);
                     cell3.SetCellType(NPOI.SS.UserModel.CellType.String);
-                    cell3.SetCellValue("Dutyid");
+                    cell3.SetCellValue("物理世界Id");
 
 
-                    ICell cell4 = row.CreateCell(3);
+                    ICell cell4 = row.CreateCell(4);
                     cell4.SetCellType(NPOI.SS.UserModel.CellType.String);
-                    cell4.SetCellValue("BIMID");
+                    cell4.SetCellValue("模型中的Id");
 
                     #endregion
 

+ 290 - 0
MBI/SAGA.MBI/ToolsData/ExportMEPSystem.cs

@@ -0,0 +1,290 @@
+/* ==============================================================================
+ * 功能描述:导出所有的岗位
+ * 创 建 者:Garrett
+ * 创建日期:2018/8/10 16:36:26
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Mechanical;
+using FWindSoft.Tools;
+using Microsoft.Win32;
+using Newtonsoft.Json.Linq;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
+using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Logger;
+using SAGA.DotNetUtils.Others;
+using SAGA.MBI.Calc;
+using SAGA.MBI.Common;
+using SAGA.MBI.DataArrange;
+using SAGA.MBI.Model;
+using SAGA.MBI.RequestData;
+using SAGA.MBI.Tools;
+using SAGA.MBI.WinView.Upload;
+using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.MEP;
+using CellType = Autodesk.Revit.DB.CellType;
+
+namespace SAGA.MBI.ToolsData
+{
+    /// <summary>
+    /// UpdateRelationEquipinFloor
+    /// </summary>
+    public class ExportMEPSystem
+    {
+        /// <summary>
+        /// 检查并处理所有楼层
+        /// </summary>
+        public static void OperateAll()
+        {
+            var floors = DalProjectTree.GetAllFloors(false);
+            List<ExportItemGroup> contexts = new List<ExportItemGroup>();
+            foreach (var floor in floors)
+            {
+                contexts.Add(Operate(floor));
+            }
+            ExportToExcel(contexts);
+        }
+        /// <summary>
+        /// 只处理当前楼层
+        /// </summary>
+        public static void OperateCurFloor()
+        {
+            MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor();
+            if (floor != null)
+            {
+                var context = Operate(floor);
+                ExportToExcel(new List<ExportItemGroup>() { context });
+            }
+        }
+        /// <summary>
+        /// 检查并处理
+        /// </summary>
+        /// <param name="floor"></param>
+        /// <returns></returns>
+        private static ExportItemGroup Operate(MFloor floor)
+        {
+            string fullPah = floor.FullPath;
+            Document doc = ExternalDataWrapper.Current.UiApp.Application.OpenDocumentFile(fullPah);
+
+            ExportItemGroup group =new ExportItemGroup(floor.ToString());
+            var systems = doc.GetElements<MEPSystem>();
+            foreach (var mepSystem in systems)
+            {
+                string name = mepSystem.Name;
+                string systemType = doc.GetElement(mepSystem.GetTypeId()).Name;
+                string type = mepSystem is MechanicalSystem ? "风管" : "水管";
+                group.Items.Add(new ExportItem(){SystemName = name,SystemType = systemType,Type = type});
+            }
+            return group;
+        }
+
+        /// <summary>
+        /// 导出数据
+        /// </summary>
+        /// <param name="xyzsList"></param>
+        static void ExportToExcel(List<ExportItemGroup> contexts)
+        {
+            SaveFileDialog sflg = new SaveFileDialog();
+            sflg.Filter = "Excel(*.xlsx)|*.xlsx";
+            sflg.FileName = $"{MBIControl.ProjectCur}系统汇总表";
+            if (sflg.ShowDialog() != true) return;
+            ExportToExcel(contexts, sflg.FileName, sflg.FilterIndex);
+        }
+
+        /// <summary>
+        /// 导出数据到指定目录
+        /// </summary>
+        /// <param name="xyzsList"></param>
+        /// <param name="fileName"></param>
+        private static void ExportToExcel(List<ExportItemGroup> contexts, string fileName, int filterIndex = 0)
+        {
+            try
+            {
+                IWorkbook book = new XSSFWorkbook();
+
+                #region 添加数据
+
+                foreach (var context in contexts)
+                {
+                    int index = 0;
+                    var floorName = context.FloorName;
+                    ISheet sheet = book.CreateSheet(floorName);
+
+                    #region 添加表头
+
+                    IRow row = sheet.CreateRow(0);
+                    NPOI.SS.UserModel.ICell cell0 = row.CreateCell(0);
+                    cell0.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell0.SetCellValue("楼层名称");
+
+                    ICell cell1 = row.CreateCell(1);
+                    cell1.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell1.SetCellValue("类型");
+
+                    ICell cell2 = row.CreateCell(2);
+                    cell2.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell2.SetCellValue("系统名称");
+
+                    ICell cell3 = row.CreateCell(3);
+                    cell3.SetCellType(NPOI.SS.UserModel.CellType.String);
+                    cell3.SetCellValue("系统类型名称");
+
+                    #endregion
+                    
+                    foreach (var item in context.Items)
+                    {
+                        string type = item.Type;
+                        string name = item.SystemName;
+                        string sytemName = item.SystemType;
+                        index++;
+
+                        row = sheet.CreateRow(index);
+
+                        ICell cell = row.CreateCell(0, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(floorName);
+
+                        cell = row.CreateCell(1, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(type);
+
+                        cell = row.CreateCell(2, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(name);
+
+                        cell = row.CreateCell(3, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(sytemName);
+                    }
+                }
+
+                #endregion
+
+                #region 写入
+
+                MemoryStream ms = new MemoryStream();
+                book.Write(ms);
+                book = null;
+
+                using (System.IO.FileStream fs = new System.IO.FileStream(fileName, FileMode.Create, FileAccess.Write))
+                {
+                    byte[] data = ms.ToArray();
+                    fs.Write(data, 0, data.Length);
+                    fs.Flush();
+                }
+                ms.Close();
+                ms.Dispose();
+
+                #endregion
+
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+        }
+
+        /// <summary>
+        /// 导出数据到指定目录
+        /// </summary>
+        /// <param name="xyzsList"></param>
+        /// <param name="fileName"></param>
+        private static void ExportToExcel2(List<CalcContext> contexts, string fileName, int filterIndex = 0)
+        {
+            try
+            {
+                IWorkbook book = new XSSFWorkbook();
+
+                #region 添加数据
+                ISheet sheet = book.CreateSheet("Summary");
+
+                #region 添加表头
+
+                IRow row = sheet.CreateRow(0);
+                NPOI.SS.UserModel.ICell cell0 = row.CreateCell(0);
+                cell0.SetCellType(NPOI.SS.UserModel.CellType.String);
+                cell0.SetCellValue("楼层名称");
+
+                ICell cell1 = row.CreateCell(1);
+                cell1.SetCellType(NPOI.SS.UserModel.CellType.String);
+                cell1.SetCellValue("类型");
+
+                ICell cell2 = row.CreateCell(2);
+                cell2.SetCellType(NPOI.SS.UserModel.CellType.String);
+                cell2.SetCellValue("总数");
+
+                List<string> list = new List<string>() { "FASE-光电感烟探测器", "FASE-智能感温探测器", "FSCP-消火栓起泵按钮" };
+                var list2 = list.Select(tt => tt.Substring(0, 4)).ToList();
+                int index = 0;
+                foreach (var context in contexts)
+                {
+                    var floorName = context.MFloor.ToString();
+
+
+                    #endregion
+                    Action<int> action = (count) =>
+                    {
+                        index++;
+
+                        row = sheet.CreateRow(index);
+
+                        ICell cell = row.CreateCell(0, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(floorName);
+
+                        cell = row.CreateCell(1, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(string.Join(",", list));
+
+                        cell = row.CreateCell(2, NPOI.SS.UserModel.CellType.String);
+                        cell.SetCellValue(count);
+
+                    };
+                    action(context.MEquipments.Where(t => list2.Contains(t.EquipClassCode)).Count());
+
+                }
+
+                #endregion
+
+                #region 写入
+
+                MemoryStream ms = new MemoryStream();
+                book.Write(ms);
+                book = null;
+
+                using (System.IO.FileStream fs = new System.IO.FileStream(fileName, FileMode.Create, FileAccess.Write))
+                {
+                    byte[] data = ms.ToArray();
+                    fs.Write(data, 0, data.Length);
+                    fs.Flush();
+                }
+                ms.Close();
+                ms.Dispose();
+
+                #endregion
+
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+        }
+
+        class ExportItemGroup
+        {
+            public ExportItemGroup(string floorName)
+            {
+                FloorName = floorName;
+                Items = new List<ExportItem>();
+            }
+            public List<ExportItem> Items { get; set; }
+            public string FloorName { get; set; }
+        }
+        class ExportItem
+        {
+            public string  SystemName { get; set; }
+            public string SystemType { get; set; }
+            public string Type { get; set; }
+        }
+    }
+}