-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRevitCopingZonesCommand.cs
116 lines (97 loc) · 4.5 KB
/
RevitCopingZonesCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using dosymep;
using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone.SimpleServices;
using dosymep.SimpleServices;
using Ninject;
using RevitCopingZones.Models;
using RevitCopingZones.ViewModels;
using RevitCopingZones.Views;
using Application = Autodesk.Revit.ApplicationServices.Application;
namespace RevitCopingZones {
[Transaction(TransactionMode.Manual)]
public class RevitCopingZonesCommand : BasePluginCommand {
public RevitCopingZonesCommand() {
PluginName = "Копирование зон СМР";
}
protected override void Execute(UIApplication uiApplication) {
using(IKernel kernel = new StandardKernel()) {
kernel.Bind<UIApplication>()
.ToConstant(uiApplication)
.InTransientScope();
kernel.Bind<Application>()
.ToConstant(uiApplication.Application)
.InTransientScope();
kernel.Bind<RevitRepository>()
.ToSelf()
.InSingletonScope();
kernel.Bind<CopingZonesConfig>()
.ToMethod(c => CopingZonesConfig.GetCheckingLevelConfig());
kernel.Bind<MainViewModel>().ToSelf();
kernel.Bind<MainWindow>().ToSelf()
.WithPropertyValue(nameof(Window.Title), PluginName)
.WithPropertyValue(nameof(Window.DataContext),
c => c.Kernel.Get<MainViewModel>());
CheckLevels();
Check(kernel);
ShowDialog(kernel);
}
}
private void Check(IKernel kernel) {
var revitRepository = kernel.Get<RevitRepository>();
if(!revitRepository.IsKoordFile()) {
TaskDialog.Show(PluginName,
$"Данный скрипт работает только в координационном файле.");
throw new OperationCanceledException();
}
if(!revitRepository.HasAreaScheme()) {
TaskDialog.Show(PluginName,
$"В открытом документе отсутствует схема зонирования с именем \"{RevitRepository.AreaSchemeName}\".");
throw new OperationCanceledException();
}
if(!revitRepository.IsAreaPlan()) {
TaskDialog.Show(PluginName, $"Активный вид не является планом зонирования.");
throw new OperationCanceledException();
}
if(!revitRepository.HasAreas()) {
TaskDialog.Show(PluginName, "На активном виде нет зон.");
throw new OperationCanceledException();
}
if(revitRepository.HasCorruptedAreas()) {
TaskDialog.Show(PluginName,
"В открытом проекте были обнаружены избыточные и не окруженные зоны, выполнение. Их следует удалить.");
throw new OperationCanceledException();
}
}
private void CheckLevels() {
var service = GetPlatformService<IPlatformCommandsService>();
string message = null;
Guid commandId = PlatformCommandIds.CheckLevelsCommandId;
Result commandResult = service.InvokeCommand(commandId, ref message, new ElementSet());
if(commandResult == Result.Failed) {
TaskDialog.Show(PluginName, message);
throw new OperationCanceledException();
}
}
private void ShowDialog(IKernel kernel) {
MainWindow window = kernel.Get<MainWindow>();
if(window.ShowDialog() == true) {
GetPlatformService<INotificationService>()
.CreateNotification(PluginName, "Выполнение скрипта завершено успешно.", "C#")
.ShowAsync();
} else {
GetPlatformService<INotificationService>()
.CreateWarningNotification(PluginName, "Выполнение скрипта отменено.")
.ShowAsync();
}
}
}
}