码迷,mamicode.com
首页 > 其他好文 > 详细

双击CAD对象(具有扩展数据),显示自定义对话框实现方法

时间:2018-03-30 23:09:51      阅读:443      评论:0      收藏:0      [点我收藏+]

标签:extension   http   objectid   using   test   document   end   set   程序   

转自:Cad人生

链接:http://www.cnblogs.com/cadlife/p/3463337.html

题目:双击CAD对象,显示自定义对话框实现方法

内容粘贴如下:

 主要是绑定两个事件:一个是 Application.DocumentManager.DocumentLockModeChanged -----  该事件为文档锁定事件,一直在被监测中
一个是 Application.BeginDoubleClick ----- 该事件为应用程序的双击事件
 1     class TlsApplication : IExtensionApplication //程序初始化,在加载dll时,cad会自动捕捉并运行该过程
  3     { 
  5         void IExtensionApplication.Initialize() 
  7         { 
  9             TTest.Start(); 
 11         } 
 13         void IExtensionApplication.Terminate() 
 15         { 
 17         } 
 19     }
 20 
 21     class TTest 
 23     { 
 25         static bool m_Veto = false; 
 27         public static void Start() 
 29         { 
 31             Application.DocumentManager.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(vetoCommand); 
 33             Application.BeginDoubleClick += new BeginDoubleClickEventHandler(beginDoubleClick); 
 35         } 
 37         static void beginDoubleClick(object sender, BeginDoubleClickEventArgs e) 
 39         { 
 41             Document doc = Application.DocumentManager.MdiActiveDocument; 
 43             Editor ed = doc.Editor; 
 45             PromptSelectionResult res = ed.SelectImplied(); 
 47             SelectionSet ss = res.Value; 
 49             if (ss != null) 
 51             { 
 53                 if (ss.Count == 1) 
 55                 { 
 57                     using (Transaction tr = doc.TransactionManager.StartTransaction()) 
 59                     { 
 61                         Line line = tr.GetObject(ss[0].ObjectId, OpenMode.ForRead) as Line; 
 63                         if (line != null) 
 65                         { 
 67                             ResultBuffer rb = line.GetXDataForApplication("MyApp"); //提取对象的扩展数据
 69                             if (rb != null) 
 71                             { 
 73                                 m_Veto = true; 
 75                             } 
 77                         } 
 79                     } 
 81                 } 
 83             } 
 85         }
 86 
 87         static void vetoCommand(object sender, DocumentLockModeChangedEventArgs e) 
 89         { 
 91             if (e.GlobalCommandName.ToLower() == "properties") //判断是否是调用属性对话框
 93             { 
 95                 if (m_Veto) 
 97                 {
 99                     e.Veto(); 
103                     Application.ShowAlertDialog("hello"); //在此处可以添加自定义对话框
105                     m_Veto = false; 
107                 } 
109             } 
111         } 
113     }

 

双击CAD对象(具有扩展数据),显示自定义对话框实现方法

标签:extension   http   objectid   using   test   document   end   set   程序   

原文地址:https://www.cnblogs.com/whlkx/p/8678779.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!