| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643 |
- /* ==============================================================================
- * 功能描述: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.DB.Plumbing;
- 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.DataArrange;
- using SAGA.MBI.Model;
- 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 SAGA.RevitUtils.MEP;
- using Line = Autodesk.Revit.DB.Line;
- using WinModeCheckSetting = SAGA.MBI.ToolsData.ModeCheck.WinModeCheckSetting;
- namespace SAGA.MBI
- {
- #region 工具
- /// <summary>
- /// 隔离立管
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class VerticalPipeIsolationCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var elems = ExternalDataWrapper.Current.UiApp.WindowSelectElement("请框选...",new CommonFilter(t =>
- {
- if (t is Pipe pipe)
- {
- var line = pipe.GetCurve() as Line;
- if (line != null)
- {
- var connectors = pipe.GetConnectors();
-
- return connectors.Any(tt=>!tt.IsConnected)&&line.Direction.IsParallel(XYZ.BasisZ);
- }
- }
- return false;
- }));
- ExternalDataWrapper.Current.UiApp.SetShowElements(elems,true);
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 立管对齐
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class VerticalPipeAlginCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- int count = 0;
- WinSelectCheckFloors win =new WinSelectCheckFloors();
- if (win.ShowDialog() == true)
- {
- VerticalPipeAlign.Instance.Execute();
- VerticalPipeAlign.Instance.ShowResult();
- }
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- public override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 批量删除无用的空间
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class DeleteZeroSpaceCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- int count = 0;
- var tip = MessageShowBase.Question2("确定要删除所有楼层周长为零的空间?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
- switch (tip)
- {
- case DialogResult.Yes:
- count=DelZeroSpace.OperateAll();
- break;
- case DialogResult.No:
- count=DelZeroSpace.OperateCurFloor();
- break;
- default:
- break;
- }
- if(tip== DialogResult.Yes||tip== DialogResult.No)
- MessageShowBase.Infomation($"此次操作共删除{count}个空间");
- }
- catch (Exception e)
- {
- MessageShow.Show(e);
- return Result.Cancelled;
- }
- return Result.Succeeded;
- }
- public override 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 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;
- }
- }
- /// <summary>
- /// 导出所有的岗位
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class ExportAllDutyCommand : 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:
- ExportAllDuty.OperateAll();
- break;
- case DialogResult.No:
- ExportAllDuty.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;
- }
- }
- #endregion
- #region 数据修正
- /// <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.Question2("确定要执行本层岗位的设备类与Revit设备族编码一致性检查?\r\n设备类与Revit设备族编码不一致,将删除岗位然后重建。");
- switch (tip)
- {
- case DialogResult.Yes:
- CheckEquipCategory.OperateAll();
- break;
- case DialogResult.No:
- CheckEquipCategory.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 override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 更新所有楼层设备的坐标信息
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class AddEquipLocationCommand : ExternalCommand
- {
- 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 override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 检查设备所在楼层关系
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class CheckEquipinFloorCommand : ExternalCommand
- {
- 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 override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 更新设备所在空间关系
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class UpdateEquipinSpaceCommand : ExternalCommand
- {
- 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 override 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)
- {
- CheckProgressBarClient.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)
- {
- CheckProgressBarClient.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
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var tip = MessageShow.Question2("是否开始修正岗位缺失问题?\r\n本功能会删除找不到对应模型的岗位和重新创建有模型没有岗位的数据。\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 override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- /// <summary>
- /// 是否开始修正BIMID重复问题
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class CorrectBIMIDDutyCommand : ExternalCommand
- {
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- try
- {
- var tip = MessageShow.Question("是否开始修正BIMID重复问题?\r\n本功能将会保留信息点最全的岗位,删除其它岗位\r\n是:开始修正全部建筑\r\n取消:取消修正。");
- if (tip)
- {
- CheckDuplicationBIMId.CorrectAll();
- MessageBox.Show("修正成功");
- }
- }
- 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 override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- #endregion
- /// <summary>
- /// 增加缺失元空间
- /// </summary>
- [Transaction(TransactionMode.Manual)]
- [Regeneration(RegenerationOption.Manual)]
- public class AddSiSpaceCommand : ExternalCommand
- {
-
- public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
- {
- List<string> errorIds = new List<string>();
- List<string> totalIds = new List<string>();
- try
- {
- var tip = MessageShow.Question("确认增加缺失元空间信息");
- if (tip)
- {
- MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor();
- if (floor != null)
- {
- var context = DalCommon.DownLoadFloorDataByBIMFloorInfo(floor);
- context.OpenDocument();
- var doc = context.RevitDoc;
- var revitSpaces = doc.GetSpaces();
- var platSpaces = context.MSpaces;
- foreach (var space in revitSpaces)
- {
- if (!space.IsSpace())
- {
- continue;
- }
- var spaceid = space.GetCloudBIMId();
- var mspace = platSpaces.FirstOrDefault(t => t.BimID == spaceid);
- if (mspace == null)
- {
- totalIds.Add(space.Id.ToString());
- mspace = DalSpace.GetSpace(space);
- mspace.Operator = DocumentChangedOperator.Add;
- if (!mspace.AddObject())
- {
- errorIds.Add(space.Id.ToString());
- }
- }
- }
-
- }
- MessageBox.Show("总共修改:"+totalIds.Count);
- if (errorIds.Any()) ;
- {
- MessageBox.Show("错误Ids:" + string.Join(";",errorIds));
- }
- }
- }
- 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 override bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
- {
- return true;
- }
- }
- }
|