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         }

 

转载于:https://www.cnblogs.com/xt112233/p/9866801.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值