-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainClass.cs
More file actions
48 lines (43 loc) · 1.52 KB
/
MainClass.cs
File metadata and controls
48 lines (43 loc) · 1.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
using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace RevitAddIn_MyProject
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class MainClass : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
try
{
//开启事务
Transaction documentTransaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "Document");
documentTransaction.Start();
//创建一个DataManager类实例
DataManager dataManager = new DataManager(commandData);
bool? dialogResult = default;
//创建一个窗体
using (MainWindow mainWindow = new MainWindow(dataManager))
{
dialogResult = mainWindow.ShowDialog();
}
if (dialogResult == true)
{
documentTransaction.Commit();
return Result.Succeeded;
}
else
{
documentTransaction.RollBack();
return Result.Cancelled;
}
}
catch (Exception e)
{
//出错处理
message = e.Message;
return Result.Failed;
}
}
}
}