123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /* ==============================================================================
- * 功能描述:ExportCombineWall
- * 创 建 者:Garrett
- * 创建日期:2017/11/21 16:21:22
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Mechanical;
- using Autodesk.Revit.UI;
- using NPOI.OpenXmlFormats;
- using NPOI.SS.Formula.Functions;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Extend;
- using SAGA.RevitUtils;
- using SAGA.RevitUtils.Extends;
- using SAGA.RevitUtils.Windows;
- using SpacePlugin.CobineWall;
- using Point = System.Windows.Point;
- namespace SpacePlugin
- {
- /// <summary>
- /// ExportCombineWall
- /// </summary>
- public class ExportCombineWall
- {
- public static void ExportWall()
- {
- var path = Path.Combine(AppBaseInfo.AppRunPath, @"MBIResource\北京市海淀区0021号项目");
- DirectoryInfo folder = new DirectoryInfo(path);
- foreach (var dicInfo in folder.GetDirectories())
- {
- FileInfo[] fileInfos = dicInfo.GetFiles("*.rvt").Where(t => !t.Name.Is000File()).ToArray();
- foreach (FileInfo file in fileInfos)
- {
- string filePath = file.FullName;
- ExportWall(filePath);
- }
- }
- }
- public static void ExportWall(string filePath)
- {
- ExportParallelWall(filePath);
- ExportVirtualizeWallResult(filePath);
- CreateSegmSpace(filePath);
- }
- /// <summary>
- /// 导出给定路径Revit文件下面的Wall
- /// </summary>
- /// <param name="path"></param>
- public static void ExportParallelWall(string path)
- {
- var uiApp = ExternalDataWrapper.Current.UiApp;
- var linkDoc = uiApp.Application.OpenDocumentFile(path);
- List<Element> linkElements = linkDoc.GetAllElements(false);
- var walls = linkElements.Where(t => t is Wall).ToList<Wall>();
- if (!walls.Any()) return;
- try
- {
- var xyzs = WallOperationFactory.GroupWallByParallel(walls).ToList();
- var fullName = path.GetAppointSuffixPath(".xlsx");
- NpoiHelper.ExportToExcel(xyzs, fullName, 0);
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- }
- }
- /// <summary>
- /// 导出虚拟墙结果
- /// </summary>
- public static void ExportVirtualizeWallResult(string path)
- {
- try
- {
- var wallPath = path.GetAppointSuffixPath(".xlsx");
- if (wallPath == null) return;
- var strAsmblPath = Path.Combine(AppBaseInfo.AppRunPath, @"MBIResource\VirtualizeWallCalc\GraphTest.exe"); ;
- // ExportCombineWall.ExportWall();
- var asmbl = Assembly.LoadFrom(strAsmblPath);
- var frmController = asmbl.CreateInstance("GraphTest.ExportVWCurves");
- if (frmController != null)
- {
- var calcMethod = frmController.GetType().GetMethod("Calc");
- calcMethod?.Invoke(frmController, new object[] { wallPath });
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- throw;
- }
- }
- /// <summary>
- /// 创建虚拟墙
- /// </summary>
- /// <param name="path"></param>
- public static void CreateVirtualizeWall(string path)
- {
- try
- {
- AutoCreateSpace.CreateSpace(path);
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- }
- }
- /// <summary>
- /// 创建虚拟墙并自动放置空间
- /// </summary>
- /// <param name="path"></param>
- public static void CreateSegmSpace(string path)
- {
- try
- {
- AutoCreateSpace.CreateSpace(path);
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- }
- }
- }
- }
|