ToolCommand.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. /* ==============================================================================
  2. * 功能描述:ToolCommand
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/7/11 14:25:22
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using Autodesk.Revit.Attributes;
  13. using Autodesk.Revit.DB;
  14. using Autodesk.Revit.DB.Plumbing;
  15. using Autodesk.Revit.UI;
  16. using DevExpress.Xpf.Core;
  17. using FWindSoft.DataFramework;
  18. using SAGA.DotNetUtils;
  19. using SAGA.DotNetUtils.Logger;
  20. using SAGA.DotNetUtils.Others;
  21. using SAGA.MBI.Common;
  22. using SAGA.MBI.DataArrange;
  23. using SAGA.MBI.Model;
  24. using SAGA.MBI.Tools;
  25. using SAGA.MBI.ToolsData;
  26. using SAGA.MBI.ToolsData.CheckBase;
  27. using SAGA.MBI.ToolsData.DataCheck;
  28. using SAGA.MBI.ToolsData.ModeCheck;
  29. using SAGA.MBI.WinView.Login;
  30. using SAGA.RevitUtils;
  31. using SAGA.RevitUtils.Extends;
  32. using SAGA.RevitUtils.MEP;
  33. using Line = Autodesk.Revit.DB.Line;
  34. using WinModeCheckSetting = SAGA.MBI.ToolsData.ModeCheck.WinModeCheckSetting;
  35. namespace SAGA.MBI
  36. {
  37. #region 工具
  38. /// <summary>
  39. /// 隔离立管
  40. /// </summary>
  41. [Transaction(TransactionMode.Manual)]
  42. [Regeneration(RegenerationOption.Manual)]
  43. public class VerticalPipeIsolationCommand : ExternalCommand
  44. {
  45. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  46. {
  47. try
  48. {
  49. var elems = ExternalDataWrapper.Current.UiApp.WindowSelectElement("请框选...",new CommonFilter(t =>
  50. {
  51. if (t is Pipe pipe)
  52. {
  53. var line = pipe.GetCurve() as Line;
  54. if (line != null)
  55. {
  56. var connectors = pipe.GetConnectors();
  57. return connectors.Any(tt=>!tt.IsConnected)&&line.Direction.IsParallel(XYZ.BasisZ);
  58. }
  59. }
  60. return false;
  61. }));
  62. ExternalDataWrapper.Current.UiApp.SetShowElements(elems,true);
  63. }
  64. catch (Exception e)
  65. {
  66. MessageShow.Show(e);
  67. return Result.Cancelled;
  68. }
  69. return Result.Succeeded;
  70. }
  71. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  72. {
  73. return true;
  74. }
  75. }
  76. /// <summary>
  77. /// 立管对齐
  78. /// </summary>
  79. [Transaction(TransactionMode.Manual)]
  80. [Regeneration(RegenerationOption.Manual)]
  81. public class VerticalPipeAlginCommand : ExternalCommand
  82. {
  83. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  84. {
  85. try
  86. {
  87. int count = 0;
  88. WinSelectCheckFloors win =new WinSelectCheckFloors();
  89. if (win.ShowDialog() == true)
  90. {
  91. VerticalPipeAlign.Instance.Execute();
  92. VerticalPipeAlign.Instance.ShowResult();
  93. }
  94. }
  95. catch (Exception e)
  96. {
  97. MessageShow.Show(e);
  98. return Result.Cancelled;
  99. }
  100. return Result.Succeeded;
  101. }
  102. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  103. {
  104. return true;
  105. }
  106. }
  107. /// <summary>
  108. /// 批量删除无用的空间
  109. /// </summary>
  110. [Transaction(TransactionMode.Manual)]
  111. [Regeneration(RegenerationOption.Manual)]
  112. public class DeleteZeroSpaceCommand : ExternalCommand
  113. {
  114. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  115. {
  116. try
  117. {
  118. int count = 0;
  119. var tip = MessageShowBase.Question2("确定要删除所有楼层周长为零的空间?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
  120. switch (tip)
  121. {
  122. case DialogResult.Yes:
  123. count=DelZeroSpace.OperateAll();
  124. break;
  125. case DialogResult.No:
  126. count=DelZeroSpace.OperateCurFloor();
  127. break;
  128. default:
  129. break;
  130. }
  131. if(tip== DialogResult.Yes||tip== DialogResult.No)
  132. MessageShowBase.Infomation($"此次操作共删除{count}个空间");
  133. }
  134. catch (Exception e)
  135. {
  136. MessageShow.Show(e);
  137. return Result.Cancelled;
  138. }
  139. return Result.Succeeded;
  140. }
  141. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  142. {
  143. return true;
  144. }
  145. }
  146. /// <summary>
  147. /// 导出类别
  148. /// </summary>
  149. [Transaction(TransactionMode.Manual)]
  150. [Regeneration(RegenerationOption.Manual)]
  151. public class ExportCategoriesCommand : ExternalCommand
  152. {
  153. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  154. {
  155. try
  156. {
  157. var tip = MessageShow.Question("确定要导出所有的族类别?");
  158. if (tip)
  159. BllFactory<ExportAllCategory>.Instance.Operate();
  160. }
  161. catch (Exception e)
  162. {
  163. MessageShow.Show(e);
  164. return Result.Cancelled;
  165. }
  166. return Result.Succeeded;
  167. }
  168. /// <summary>
  169. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  170. /// when a document is open.
  171. /// </summary>
  172. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  173. {
  174. return true;
  175. }
  176. }
  177. /// <summary>
  178. /// 报告设备所在空间
  179. /// </summary>
  180. [Transaction(TransactionMode.Manual)]
  181. [Regeneration(RegenerationOption.Manual)]
  182. public class ReportEquipInSpaceCommand : ExternalCommand
  183. {
  184. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  185. {
  186. try
  187. {
  188. var fi = ExternalDataWrapper.Current.UiApp.GetSelectedElement() as FamilyInstance;
  189. var space = fi.GetReferenceSpace();
  190. MessageShowBase.Infomation($"设备所在空间Id为{space?.Id}");
  191. }
  192. catch (Exception e)
  193. {
  194. MessageShow.Show(e);
  195. return Result.Cancelled;
  196. }
  197. return Result.Succeeded;
  198. }
  199. }
  200. /// <summary>
  201. /// 导出所有的岗位
  202. /// </summary>
  203. [Transaction(TransactionMode.Manual)]
  204. [Regeneration(RegenerationOption.Manual)]
  205. public class ExportAllDutyCommand : ExternalCommand
  206. {
  207. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  208. {
  209. try
  210. {
  211. var tip = MessageShowBase.Question2("确定要导出所有岗位?\r\n是:全部楼层\r\n否:当前楼层\r\n取消:取消。");
  212. switch (tip)
  213. {
  214. case DialogResult.Yes:
  215. ExportAllDuty.OperateAll();
  216. break;
  217. case DialogResult.No:
  218. ExportAllDuty.OperateCurFloor();
  219. break;
  220. default:
  221. break;
  222. }
  223. }
  224. catch (Exception e)
  225. {
  226. MessageShow.Show(e);
  227. return Result.Cancelled;
  228. }
  229. return Result.Succeeded;
  230. }
  231. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  232. {
  233. return true;
  234. }
  235. }
  236. #endregion
  237. #region 数据修正
  238. /// <summary>
  239. /// 修正云平台族类型和本地族类型不一致
  240. /// </summary>
  241. [Transaction(TransactionMode.Manual)]
  242. [Regeneration(RegenerationOption.Manual)]
  243. public class CheckCloudAndLocalFamilyCommand : ExternalCommand
  244. {
  245. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  246. {
  247. try
  248. {
  249. var tip = MessageShow.Question2("确定要执行本层岗位的设备类与Revit设备族编码一致性检查?\r\n设备类与Revit设备族编码不一致,将删除岗位然后重建。");
  250. switch (tip)
  251. {
  252. case DialogResult.Yes:
  253. CheckEquipCategory.OperateAll();
  254. break;
  255. case DialogResult.No:
  256. CheckEquipCategory.OperateCurFloor();
  257. break;
  258. default:
  259. break;
  260. }
  261. }
  262. catch (Exception e)
  263. {
  264. MessageShow.Show(e);
  265. return Result.Cancelled;
  266. }
  267. return Result.Succeeded;
  268. }
  269. /// <summary>
  270. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  271. /// when a document is open.
  272. /// </summary>
  273. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  274. {
  275. return true;
  276. }
  277. }
  278. /// <summary>
  279. /// 更新所有楼层设备的坐标信息
  280. /// </summary>
  281. [Transaction(TransactionMode.Manual)]
  282. [Regeneration(RegenerationOption.Manual)]
  283. public class AddEquipLocationCommand : ExternalCommand
  284. {
  285. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  286. {
  287. try
  288. {
  289. var tip = MessageShow.Question2("确定要更新所有楼层设备的坐标信息?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
  290. switch (tip)
  291. {
  292. case DialogResult.Yes:
  293. AddEquipLocation.OperateAll();
  294. break;
  295. case DialogResult.No:
  296. AddEquipLocation.OperateCurFloor();
  297. break;
  298. default:
  299. break;
  300. }
  301. }
  302. catch (Exception e)
  303. {
  304. MessageShow.Show(e);
  305. return Result.Cancelled;
  306. }
  307. return Result.Succeeded;
  308. }
  309. /// <summary>
  310. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  311. /// when a document is open.
  312. /// </summary>
  313. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  314. {
  315. return true;
  316. }
  317. }
  318. /// <summary>
  319. /// 检查设备所在楼层关系
  320. /// </summary>
  321. [Transaction(TransactionMode.Manual)]
  322. [Regeneration(RegenerationOption.Manual)]
  323. public class CheckEquipinFloorCommand : ExternalCommand
  324. {
  325. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  326. {
  327. try
  328. {
  329. var tip = MessageShow.Question("确定要执行所有楼层设备所在楼层关系检查?");
  330. if (tip)
  331. UpdateRelationEquipinFloor.OperateAll(); ;
  332. }
  333. catch (Exception e)
  334. {
  335. MessageShow.Show(e);
  336. return Result.Cancelled;
  337. }
  338. return Result.Succeeded;
  339. }
  340. /// <summary>
  341. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  342. /// when a document is open.
  343. /// </summary>
  344. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  345. {
  346. return true;
  347. }
  348. }
  349. /// <summary>
  350. /// 更新设备所在空间关系
  351. /// </summary>
  352. [Transaction(TransactionMode.Manual)]
  353. [Regeneration(RegenerationOption.Manual)]
  354. public class UpdateEquipinSpaceCommand : ExternalCommand
  355. {
  356. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  357. {
  358. try
  359. {
  360. var tip = MessageShow.Question2("确定要更新设备所在空间关系?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
  361. switch (tip)
  362. {
  363. case DialogResult.Yes:
  364. UpdateRelationEquipinSpace.OperateAll();
  365. break;
  366. case DialogResult.No:
  367. UpdateRelationEquipinSpace.OperateCurFloor();
  368. break;
  369. default:
  370. break;
  371. }
  372. }
  373. catch (Exception e)
  374. {
  375. MessageShow.Show(e);
  376. return Result.Cancelled;
  377. }
  378. return Result.Succeeded;
  379. }
  380. /// <summary>
  381. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  382. /// when a document is open.
  383. /// </summary>
  384. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  385. {
  386. return true;
  387. }
  388. }
  389. /// <summary>
  390. /// 模型规范检查
  391. /// </summary>
  392. [Transaction(TransactionMode.Manual)]
  393. [Regeneration(RegenerationOption.Manual)]
  394. public class ModeSpecificationCheckCommand : ExternalCommand, IExternalCommandAvailability
  395. {
  396. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  397. {
  398. try
  399. {
  400. var checkType = CheckType.ModeCheck;
  401. var checkItems = CheckOperation.GetCheckItems(checkType);
  402. WinModeCheckSetting win = new WinModeCheckSetting(checkItems, checkType);
  403. if (win.ShowDialog() != true) return Result.Cancelled;
  404. CheckOperation.Execute(checkItems, win.GetCheckContext());
  405. }
  406. catch (Exception e)
  407. {
  408. CheckProgressBarClient.Stop();
  409. MessageShow.Show(e);
  410. return Result.Cancelled;
  411. }
  412. return Result.Succeeded;
  413. }
  414. /// <summary>
  415. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  416. /// when a document is open.
  417. /// </summary>
  418. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  419. {
  420. return true;
  421. }
  422. }
  423. /// <summary>
  424. /// 垃圾数据检查
  425. /// </summary>
  426. [Transaction(TransactionMode.Manual)]
  427. [Regeneration(RegenerationOption.Manual)]
  428. public class JunkDataCheckCommand : ExternalCommand, IExternalCommandAvailability
  429. {
  430. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  431. {
  432. try
  433. {
  434. var checkType = CheckType.DataCheck;
  435. var checkItems = CheckOperation.GetCheckItems(checkType);
  436. WinDataCheckSetting win = new WinDataCheckSetting(checkItems, CheckType.DataCheck);
  437. if (win.ShowDialog() != true) return Result.Cancelled;
  438. CheckOperation.Execute(checkItems, win.GetCheckContext());
  439. }
  440. catch (Exception e)
  441. {
  442. CheckProgressBarClient.Stop();
  443. MessageShow.Show(e);
  444. return Result.Cancelled;
  445. }
  446. return Result.Succeeded;
  447. }
  448. /// <summary>
  449. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  450. /// when a document is open.
  451. /// </summary>
  452. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  453. {
  454. return true;
  455. }
  456. }
  457. /// <summary>
  458. /// 修正岗位缺失
  459. /// </summary>
  460. [Transaction(TransactionMode.Manual)]
  461. [Regeneration(RegenerationOption.Manual)]
  462. public class CorrectLossDutyCommand : ExternalCommand
  463. {
  464. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  465. {
  466. try
  467. {
  468. var tip = MessageShow.Question2("是否开始修正岗位缺失问题?\r\n本功能会删除找不到对应模型的岗位和重新创建有模型没有岗位的数据。\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
  469. switch (tip)
  470. {
  471. case DialogResult.Yes:
  472. CorrectLossDuty.OperateAll();
  473. break;
  474. case DialogResult.No:
  475. CorrectLossDuty.OperateCurFloor();
  476. break;
  477. default:
  478. break;
  479. }
  480. }
  481. catch (Exception e)
  482. {
  483. MessageShow.Show(e);
  484. return Result.Cancelled;
  485. }
  486. return Result.Succeeded;
  487. }
  488. /// <summary>
  489. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  490. /// when a document is open.
  491. /// </summary>
  492. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  493. {
  494. return true;
  495. }
  496. }
  497. /// <summary>
  498. /// 是否开始修正BIMID重复问题
  499. /// </summary>
  500. [Transaction(TransactionMode.Manual)]
  501. [Regeneration(RegenerationOption.Manual)]
  502. public class CorrectBIMIDDutyCommand : ExternalCommand
  503. {
  504. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  505. {
  506. try
  507. {
  508. var tip = MessageShow.Question("是否开始修正BIMID重复问题?\r\n本功能将会保留信息点最全的岗位,删除其它岗位\r\n是:开始修正全部建筑\r\n取消:取消修正。");
  509. if (tip)
  510. {
  511. CheckDuplicationBIMId.CorrectAll();
  512. MessageBox.Show("修正成功");
  513. }
  514. }
  515. catch (Exception e)
  516. {
  517. MessageShow.Show(e);
  518. return Result.Cancelled;
  519. }
  520. return Result.Succeeded;
  521. }
  522. /// <summary>
  523. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  524. /// when a document is open.
  525. /// </summary>
  526. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  527. {
  528. return true;
  529. }
  530. }
  531. #endregion
  532. /// <summary>
  533. /// 增加缺失元空间
  534. /// </summary>
  535. [Transaction(TransactionMode.Manual)]
  536. [Regeneration(RegenerationOption.Manual)]
  537. public class AddSiSpaceCommand : ExternalCommand
  538. {
  539. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  540. {
  541. List<string> errorIds = new List<string>();
  542. List<string> totalIds = new List<string>();
  543. try
  544. {
  545. var tip = MessageShow.Question("确认增加缺失元空间信息");
  546. if (tip)
  547. {
  548. MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor();
  549. if (floor != null)
  550. {
  551. var context = DalCommon.DownLoadFloorDataByBIMFloorInfo(floor);
  552. context.OpenDocument();
  553. var doc = context.RevitDoc;
  554. var revitSpaces = doc.GetSpaces();
  555. var platSpaces = context.MSpaces;
  556. foreach (var space in revitSpaces)
  557. {
  558. if (!space.IsSpace())
  559. {
  560. continue;
  561. }
  562. var spaceid = space.GetCloudBIMId();
  563. var mspace = platSpaces.FirstOrDefault(t => t.BimID == spaceid);
  564. if (mspace == null)
  565. {
  566. totalIds.Add(space.Id.ToString());
  567. mspace = DalSpace.GetSpace(space);
  568. mspace.Operator = DocumentChangedOperator.Add;
  569. if (!mspace.AddObject())
  570. {
  571. errorIds.Add(space.Id.ToString());
  572. }
  573. }
  574. }
  575. }
  576. MessageBox.Show("总共修改:"+totalIds.Count);
  577. if (errorIds.Any()) ;
  578. {
  579. MessageBox.Show("错误Ids:" + string.Join(";",errorIds));
  580. }
  581. }
  582. }
  583. catch (Exception e)
  584. {
  585. MessageShow.Show(e);
  586. return Result.Cancelled;
  587. }
  588. return Result.Succeeded;
  589. }
  590. /// <summary>
  591. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  592. /// when a document is open.
  593. /// </summary>
  594. public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  595. {
  596. return true;
  597. }
  598. }
  599. }