123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- /* ==============================================================================
- * 功能描述:ToolCommand
- * 创 建 者:Garrett
- * 创建日期:2018/7/11 14:25:22
- * ==============================================================================*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Autodesk.Revit.Attributes;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.UI;
- using DevExpress.Xpf.Core;
- using FWindSoft.DataFramework;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Logger;
- using SAGA.DotNetUtils.Others;
- using SAGA.MBI.Common;
- using SAGA.MBI.Tools;
- using SAGA.MBI.ToolsData;
- using SAGA.MBI.ToolsData.CheckBase;
- using SAGA.MBI.ToolsData.DataCheck;
- using SAGA.MBI.ToolsData.ModeCheck;
- using SAGA.MBI.WinView.Login;
- using SAGA.RevitUtils;
- using SAGA.RevitUtils.Extends;
- using WinModeCheckSetting = SAGA.MBI.ToolsData.ModeCheck.WinModeCheckSetting;
- namespace SAGA.MBI
- {
- #region 工具
- /// <summary>
- /// 批量删除无用的空间
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class DeleteZeroSpaceCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var doc = ExternalDataWrapper.Current.Doc;
- using (Transaction trans = new Transaction(doc, "删除"))
- {
- 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();
- }
- }
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- }
- /// <summary>
- /// 报告设备所在空间
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class ReportEquipInSpaceCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var fi = ExternalDataWrapper.Current.UiApp.GetSelectedElement() as FamilyInstance;
- var space = fi.GetReferenceSpace();
- MessageShowBase.Infomation($"设备所在空间Id为{space?.Id}");
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- }
- #endregion
- /// <summary>
- /// 修正云平台族类型和本地族类型不一致
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class CheckCloudAndLocalFamilyCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var tip = MessageShow.Question("确定要执行本层岗位的设备类与Revit设备族编码一致性检查?\r\n设备类与Revit设备族编码不一致,将删除岗位然后重建。");
- if (tip)
- CheckEquipCategory.OperateCurFloor();
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return false;
- }
- }
- /// <summary>
- /// 更新所有楼层设备的坐标信息
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class AddEquipLocationCommand : ExternalCommand, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var tip = MessageShow.Question2("确定要更新所有楼层设备的坐标信息?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
- switch (tip)
- {
- case DialogResult.Yes:
- AddEquipLocation.OperateAll();
- break;
- case DialogResult.No:
- AddEquipLocation.OperateCurFloor();
- break;
- default:
- break;
- }
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 检查设备所在楼层关系
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class CheckEquipinFloorCommand : ExternalCommand, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var tip = MessageShow.Question("确定要执行所有楼层设备所在楼层关系检查?");
- if (tip)
- UpdateRelationEquipinFloor.OperateAll(); ;
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 更新设备所在空间关系
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class UpdateEquipinSpaceCommand : ExternalCommand, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var tip = MessageShow.Question2("确定要更新设备所在空间关系?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
- switch (tip)
- {
- case DialogResult.Yes:
- UpdateRelationEquipinSpace.OperateAll();
- break;
- case DialogResult.No:
- UpdateRelationEquipinSpace.OperateCurFloor();
- break;
- default:
- break;
- }
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 导出类别
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class ExportCategoriesCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var tip = MessageShow.Question("确定要导出所有的族类别?");
- if (tip)
- BllFactory<ExportAllCategory>.Instance.Operate();
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 模型规范检查
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class ModeSpecificationCheckCommand : ExternalCommand, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var checkType = CheckType.ModeCheck;
- var checkItems = CheckOperation.GetCheckItems(checkType);
- WinModeCheckSetting win = new WinModeCheckSetting(checkItems, checkType);
- if (win.ShowDialog() != true) return Result.Cancelled;
- CheckOperation.Execute(checkItems, win.GetCheckContext());
- }
- catch (Exception e)
- {
- DataCheckProgressBarClient.Stop();
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 垃圾数据检查
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class JunkDataCheckCommand : ExternalCommand, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var checkType = CheckType.DataCheck;
- var checkItems = CheckOperation.GetCheckItems(checkType);
- WinDataCheckSetting win = new WinDataCheckSetting(checkItems, CheckType.DataCheck);
- if (win.ShowDialog() != true) return Result.Cancelled;
- CheckOperation.Execute(checkItems, win.GetCheckContext());
- }
- catch (Exception e)
- {
- DataCheckProgressBarClient.Stop();
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 修正岗位缺失
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class CorrectLossDutyCommand : ExternalCommand, IExternalCommandAvailability
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var tip = MessageShow.Question2("是否开始修正岗位缺失问题?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
- switch (tip)
- {
- case DialogResult.Yes:
- CorrectLossDuty.OperateAll();
- break;
- case DialogResult.No:
- CorrectLossDuty.OperateCurFloor();
- break;
- default:
- break;
- }
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- /// <summary>
- /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
- /// when a document is open.
- /// </summary>
- public bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- }
|