-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathRevitExamplePluginCommand.cs
More file actions
71 lines (58 loc) · 2.52 KB
/
RevitExamplePluginCommand.cs
File metadata and controls
71 lines (58 loc) · 2.52 KB
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
using System;
using System.Globalization;
using System.Reflection;
using System.Windows;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using dosymep.Bim4Everyone;
using dosymep.Bim4Everyone.SimpleServices;
using dosymep.SimpleServices;
using dosymep.WPF.Views;
using dosymep.Xpf.Core.Ninject;
using Ninject;
using RevitExamplePlugin.Models;
using RevitExamplePlugin.ViewModels;
using RevitExamplePlugin.Views;
namespace RevitExamplePlugin {
[Transaction(TransactionMode.Manual)]
public class RevitExamplePluginCommand : BasePluginCommand {
public RevitExamplePluginCommand() {
PluginName = "C# Button";
}
protected override void Execute(UIApplication uiApplication) {
using(IKernel kernel = uiApplication.CreatePlatformServices()) {
kernel.Bind<WallRevitRepository>()
.ToSelf()
.InSingletonScope();
kernel.Bind<PluginConfig>()
.ToMethod(c => PluginConfig.GetPluginConfig());
kernel.Bind<MainViewModel>().ToSelf();
kernel.Bind<MainWindow>().ToSelf()
.WithPropertyValue(nameof(Window.DataContext),
c => c.Kernel.Get<MainViewModel>())
.WithPropertyValue(nameof(PlatformWindow.LocalizationService),
c => c.Kernel.Get<ILocalizationService>());
string assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
kernel.UseXtraLocalization(
$"/{assemblyName};component/Localization/Language.xaml",
CultureInfo.GetCultureInfo("ru-RU"));
CheckViews(kernel);
Notification(kernel.Get<MainWindow>());
}
}
private void CheckViews(IKernel kernel) {
var wallRepository = kernel.Get<WallRevitRepository>();
var localizationService = kernel.Get<ILocalizationService>();
if(!wallRepository.ActiveViewIsPlan()) {
var messageBoxService = kernel.Get<IMessageBoxService>();
messageBoxService.Show(
localizationService.GetLocalizedString("TaskDialog.ActiveViewUserPromt"),
localizationService.GetLocalizedString("TaskDialog.ActiveViewTitle"),
MessageBoxButton.OK,
MessageBoxImage.Error);
throw new OperationCanceledException();
}
}
}
}