ToolCommand.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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.UI;
  15. using DevExpress.Xpf.Core;
  16. using FWindSoft.DataFramework;
  17. using SAGA.DotNetUtils;
  18. using SAGA.DotNetUtils.Logger;
  19. using SAGA.DotNetUtils.Others;
  20. using SAGA.MBI.Common;
  21. using SAGA.MBI.Tools;
  22. using SAGA.MBI.ToolsData;
  23. using SAGA.MBI.ToolsData.CheckBase;
  24. using SAGA.MBI.ToolsData.DataCheck;
  25. using SAGA.MBI.ToolsData.ModeCheck;
  26. using SAGA.MBI.WinView.Login;
  27. using SAGA.RevitUtils;
  28. using SAGA.RevitUtils.Extends;
  29. using WinModeCheckSetting = SAGA.MBI.ToolsData.ModeCheck.WinModeCheckSetting;
  30. namespace SAGA.MBI
  31. {
  32. #region 工具
  33. /// <summary>
  34. /// 批量删除无用的空间
  35. /// </summary>
  36. [Transaction(TransactionMode.Manual)]
  37. [Regeneration(RegenerationOption.Manual)]
  38. public class DeleteZeroSpaceCommand : ExternalCommand
  39. {
  40. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  41. {
  42. try
  43. {
  44. var doc = ExternalDataWrapper.Current.Doc;
  45. using (Transaction trans = new Transaction(doc, "删除"))
  46. {
  47. trans.Start();
  48. try
  49. {
  50. var spaces = doc.GetSpaces().Where(t => t.IsDeleteSpace());
  51. doc.Delete(spaces.Select(t => t.Id).ToList());
  52. trans.Commit();
  53. MessageShowBase.Infomation("删除成功");
  54. }
  55. catch (Exception)
  56. {
  57. trans.RollBack();
  58. }
  59. }
  60. }
  61. catch (Exception e)
  62. {
  63. MessageShow.Show(e);
  64. return Result.Cancelled;
  65. }
  66. return Result.Succeeded;
  67. }
  68. }
  69. /// <summary>
  70. /// 报告设备所在空间
  71. /// </summary>
  72. [Transaction(TransactionMode.Manual)]
  73. [Regeneration(RegenerationOption.Manual)]
  74. public class ReportEquipInSpaceCommand : ExternalCommand
  75. {
  76. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  77. {
  78. try
  79. {
  80. var fi = ExternalDataWrapper.Current.UiApp.GetSelectedElement() as FamilyInstance;
  81. var space = fi.GetReferenceSpace();
  82. MessageShowBase.Infomation($"设备所在空间Id为{space?.Id}");
  83. }
  84. catch (Exception e)
  85. {
  86. MessageShow.Show(e);
  87. return Result.Cancelled;
  88. }
  89. return Result.Succeeded;
  90. }
  91. }
  92. #endregion
  93. /// <summary>
  94. /// 修正云平台族类型和本地族类型不一致
  95. /// </summary>
  96. [Transaction(TransactionMode.Manual)]
  97. [Regeneration(RegenerationOption.Manual)]
  98. public class CheckCloudAndLocalFamilyCommand : ExternalCommand
  99. {
  100. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  101. {
  102. try
  103. {
  104. var tip = MessageShow.Question("确定要执行本层岗位的设备类与Revit设备族编码一致性检查?\r\n设备类与Revit设备族编码不一致,将删除岗位然后重建。");
  105. if (tip)
  106. CheckEquipCategory.OperateCurFloor();
  107. }
  108. catch (Exception e)
  109. {
  110. MessageShow.Show(e);
  111. return Result.Cancelled;
  112. }
  113. return Result.Succeeded;
  114. }
  115. /// <summary>
  116. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  117. /// when a document is open.
  118. /// </summary>
  119. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  120. {
  121. return false;
  122. }
  123. }
  124. /// <summary>
  125. /// 更新所有楼层设备的坐标信息
  126. /// </summary>
  127. [Transaction(TransactionMode.Manual)]
  128. [Regeneration(RegenerationOption.Manual)]
  129. public class AddEquipLocationCommand : ExternalCommand, IExternalCommandAvailability
  130. {
  131. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  132. {
  133. try
  134. {
  135. var tip = MessageShow.Question2("确定要更新所有楼层设备的坐标信息?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
  136. switch (tip)
  137. {
  138. case DialogResult.Yes:
  139. AddEquipLocation.OperateAll();
  140. break;
  141. case DialogResult.No:
  142. AddEquipLocation.OperateCurFloor();
  143. break;
  144. default:
  145. break;
  146. }
  147. }
  148. catch (Exception e)
  149. {
  150. MessageShow.Show(e);
  151. return Result.Cancelled;
  152. }
  153. return Result.Succeeded;
  154. }
  155. /// <summary>
  156. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  157. /// when a document is open.
  158. /// </summary>
  159. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  160. {
  161. return true;
  162. }
  163. }
  164. /// <summary>
  165. /// 检查设备所在楼层关系
  166. /// </summary>
  167. [Transaction(TransactionMode.Manual)]
  168. [Regeneration(RegenerationOption.Manual)]
  169. public class CheckEquipinFloorCommand : ExternalCommand, IExternalCommandAvailability
  170. {
  171. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  172. {
  173. try
  174. {
  175. var tip = MessageShow.Question("确定要执行所有楼层设备所在楼层关系检查?");
  176. if (tip)
  177. UpdateRelationEquipinFloor.OperateAll(); ;
  178. }
  179. catch (Exception e)
  180. {
  181. MessageShow.Show(e);
  182. return Result.Cancelled;
  183. }
  184. return Result.Succeeded;
  185. }
  186. /// <summary>
  187. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  188. /// when a document is open.
  189. /// </summary>
  190. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  191. {
  192. return true;
  193. }
  194. }
  195. /// <summary>
  196. /// 更新设备所在空间关系
  197. /// </summary>
  198. [Transaction(TransactionMode.Manual)]
  199. [Regeneration(RegenerationOption.Manual)]
  200. public class UpdateEquipinSpaceCommand : ExternalCommand, IExternalCommandAvailability
  201. {
  202. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  203. {
  204. try
  205. {
  206. var tip = MessageShow.Question2("确定要更新设备所在空间关系?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
  207. switch (tip)
  208. {
  209. case DialogResult.Yes:
  210. UpdateRelationEquipinSpace.OperateAll();
  211. break;
  212. case DialogResult.No:
  213. UpdateRelationEquipinSpace.OperateCurFloor();
  214. break;
  215. default:
  216. break;
  217. }
  218. }
  219. catch (Exception e)
  220. {
  221. MessageShow.Show(e);
  222. return Result.Cancelled;
  223. }
  224. return Result.Succeeded;
  225. }
  226. /// <summary>
  227. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  228. /// when a document is open.
  229. /// </summary>
  230. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  231. {
  232. return true;
  233. }
  234. }
  235. /// <summary>
  236. /// 导出类别
  237. /// </summary>
  238. [Transaction(TransactionMode.Manual)]
  239. [Regeneration(RegenerationOption.Manual)]
  240. public class ExportCategoriesCommand : ExternalCommand
  241. {
  242. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  243. {
  244. try
  245. {
  246. var tip = MessageShow.Question("确定要导出所有的族类别?");
  247. if (tip)
  248. BllFactory<ExportAllCategory>.Instance.Operate();
  249. }
  250. catch (Exception e)
  251. {
  252. MessageShow.Show(e);
  253. return Result.Cancelled;
  254. }
  255. return Result.Succeeded;
  256. }
  257. /// <summary>
  258. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  259. /// when a document is open.
  260. /// </summary>
  261. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  262. {
  263. return true;
  264. }
  265. }
  266. /// <summary>
  267. /// 模型规范检查
  268. /// </summary>
  269. [Transaction(TransactionMode.Manual)]
  270. [Regeneration(RegenerationOption.Manual)]
  271. public class ModeSpecificationCheckCommand : ExternalCommand, IExternalCommandAvailability
  272. {
  273. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  274. {
  275. try
  276. {
  277. var checkType = CheckType.ModeCheck;
  278. var checkItems = CheckOperation.GetCheckItems(checkType);
  279. WinModeCheckSetting win = new WinModeCheckSetting(checkItems, checkType);
  280. if (win.ShowDialog() != true) return Result.Cancelled;
  281. CheckOperation.Execute(checkItems, win.GetCheckContext());
  282. }
  283. catch (Exception e)
  284. {
  285. DataCheckProgressBarClient.Stop();
  286. MessageShow.Show(e);
  287. return Result.Cancelled;
  288. }
  289. return Result.Succeeded;
  290. }
  291. /// <summary>
  292. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  293. /// when a document is open.
  294. /// </summary>
  295. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  296. {
  297. return true;
  298. }
  299. }
  300. /// <summary>
  301. /// 垃圾数据检查
  302. /// </summary>
  303. [Transaction(TransactionMode.Manual)]
  304. [Regeneration(RegenerationOption.Manual)]
  305. public class JunkDataCheckCommand : ExternalCommand, IExternalCommandAvailability
  306. {
  307. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  308. {
  309. try
  310. {
  311. var checkType = CheckType.DataCheck;
  312. var checkItems = CheckOperation.GetCheckItems(checkType);
  313. WinDataCheckSetting win = new WinDataCheckSetting(checkItems, CheckType.DataCheck);
  314. if (win.ShowDialog() != true) return Result.Cancelled;
  315. CheckOperation.Execute(checkItems, win.GetCheckContext());
  316. }
  317. catch (Exception e)
  318. {
  319. DataCheckProgressBarClient.Stop();
  320. MessageShow.Show(e);
  321. return Result.Cancelled;
  322. }
  323. return Result.Succeeded;
  324. }
  325. /// <summary>
  326. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  327. /// when a document is open.
  328. /// </summary>
  329. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  330. {
  331. return true;
  332. }
  333. }
  334. /// <summary>
  335. /// 修正岗位缺失
  336. /// </summary>
  337. [Transaction(TransactionMode.Manual)]
  338. [Regeneration(RegenerationOption.Manual)]
  339. public class CorrectLossDutyCommand : ExternalCommand, IExternalCommandAvailability
  340. {
  341. public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
  342. {
  343. try
  344. {
  345. var tip = MessageShow.Question2("是否开始修正岗位缺失问题?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
  346. switch (tip)
  347. {
  348. case DialogResult.Yes:
  349. CorrectLossDuty.OperateAll();
  350. break;
  351. case DialogResult.No:
  352. CorrectLossDuty.OperateCurFloor();
  353. break;
  354. default:
  355. break;
  356. }
  357. }
  358. catch (Exception e)
  359. {
  360. MessageShow.Show(e);
  361. return Result.Cancelled;
  362. }
  363. return Result.Succeeded;
  364. }
  365. /// <summary>
  366. /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
  367. /// when a document is open.
  368. /// </summary>
  369. public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
  370. {
  371. return true;
  372. }
  373. }
  374. }