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 @   邢韬  阅读(903)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
点击右上角即可分享
微信分享提示