revit二次开发之winform无法执行事务

参考:

Revit二次开发——非模态窗口:https://blog.csdn.net/niuge8905/article/details/79767671

 

想用winform读取文件数据,直接使用却又提示无法执行事务模式,所以需要注册个事件

 

 1  public class ExecuteEvent : IExternalEventHandler
 2     {
 3 
 4 
 5         public string Name { get; private set; }
 6 
 7         public Action<UIApplication> ExecuteAction { get; set; }
 8 
 9         public ExecuteEvent(string name)
10         {
11             Name = name;
12         }
13 
14         public void Execute(UIApplication app)
15         {
16 
17 
18             if (ExecuteAction != null)
19             {
20                 try
21                 {
22                     ExecuteAction(app);
23                 }
24                 catch
25                 { }
26             }
27         }
28 
29         public string GetName()
30         {
31             return Name;
32 
33         }
34     }
 1 private void Start_Click(object sender, EventArgs e)
 2         {
 3             if (ExternalEvent != null)
 4             {
 5                 ExecuteEvent.ExecuteAction = new Action<UIApplication>((app) =>
 6                 {
 7                     if (app.ActiveUIDocument == null || app.ActiveUIDocument.Document == null)
 8                         return;
 9 
10                     UIApplication uiApp = cmdDataForm.Application;
11                     Autodesk.Revit.ApplicationServices.Application application = uiApp.Application;
12                     UIDocument uiDocument = uiApp.ActiveUIDocument;
13                     Document document = uiDocument.Document;
14 
15                     object[,] length = { };
16 
17                     length = ReadExcel.Read(PathText.Text);
18 
19                     using (BottomSupport bottomSupport = new BottomSupport())
20                     {   //创建底托
21                         bottomSupport.CreateBottomSupport(document, length);
22                     }
23                     using (Vertical vertical = new Vertical())
24                     {   //创建竖杆
25                         vertical.CreateVertical(document, length);
26                     }
27                     using (NewRail newRail = new NewRail())
28                     {   //创建纵向横杆
29                         newRail.CreateRail(document, length);
30                     }
31                     using (Rail rail = new Rail())
32                     {   //创建横杆
33                         rail.CreateRail(document, length);
34                     }
35 
36                     using (Diagonal diagonal = new Diagonal())
37                     {   //创建斜杆
38                         diagonal.CreateDiagonal(document, length);
39                     }
40 
41                     using (Disc disc = new Disc())
42                     {   //创建圆盘
43                         disc.CreateDisc(document, length);
44                     }
45                     using (TopSupport topSupport = new TopSupport())
46                     {   //创建顶托
47                         topSupport.CreateTopSupport(document, length);
48                     }
49 
50                     MessageBox.Show("OK了,可以去检查一下有没有错误了");
51 
52                 });
53                 ExternalEvent.Raise();
54             }
55         }

 

posted @ 2018-10-28 19:52  邢韬  阅读(892)  评论(0编辑  收藏  举报