雪山飞狐_lzh
发表于 2009-5-30 16:05:00
本帖最后由 作者 于 2009-5-31 11:17:58 编辑
Com的版本,引用两个类型库
using System;
using System.Collections.Generic;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
namespace CadTest
{
class TlsApplication : IExtensionApplication
{
void IExtensionApplication.Initialize()
{
TTest.Start();
}
void IExtensionApplication.Terminate()
{
}
}
class TTest
{
static bool m_DbClick = false;
static Dictionary<IntPtr, AcadDocument> m_AcadDocs = new Dictionary<IntPtr, AcadDocument>();
public static void Start()
{
foreach (Document doc in Application.DocumentManager)
{
AcadDocument acaddoc = (AcadDocument)doc.AcadDocument;
m_AcadDocs.Add(doc.Window.Handle, acaddoc);
acaddoc.BeginDoubleClick += new _DAcadDocumentEvents_BeginDoubleClickEventHandler(beginDoubleClick);
}
Application.DocumentManager.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(vetoCommand);
Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(documentCreated);
}
static void documentCreated(object sender, DocumentCollectionEventArgs e)
{
Document doc = e.Document;
AcadDocument acaddoc = (AcadDocument)doc.AcadDocument;
m_AcadDocs.Add(doc.Window.Handle, acaddoc);
acaddoc.BeginDoubleClick += new _DAcadDocumentEvents_BeginDoubleClickEventHandler(beginDoubleClick);
}
static void beginDoubleClick(object PickPoint)
{
IntPtr ip = Application.DocumentManager.MdiActiveDocument.Window.Handle;
if (m_AcadDocs.ContainsKey(ip))
{
AcadDocument doc = m_AcadDocs;
AcadSelectionSet ss = doc.PickfirstSelectionSet;
if (ss.Count == 1)
{
AcadLine line = ss.Item(0) as AcadLine;
if (line != null)
{
object xt;
object xd;
line.GetXData("MyApp", out xt, out xd);
object[] datas = (object[])xd;
Application.ShowAlertDialog("数目共" + datas.ToString());
m_DbClick = true;
return;
}
}
}
m_DbClick = false;
}
static void vetoCommand(object sender, DocumentLockModeChangedEventArgs e)
{
if (m_DbClick)
{
switch (e.GlobalCommandName.ToLower())
{
case "properties":
m_DbClick = false;
e.Veto();
break;
}
}
}
}
}
xwjljh
发表于 2009-5-30 21:46:00
<p>您好,Com的版本的VB.net代码怎么实现呀?谢谢了</p><p></p>
雪山飞狐_lzh
发表于 2009-5-30 22:03:00
<p>VB.Net好久没用了,快忘光了:)</p><p>把步骤说下吧</p><p>TTest.Start方法中</p><p>重载Application.DocumentManager.DocumentCreated事件,</p><p>在新建文档时把当前文档的Com实例加入集合里</p><p>然后重载新建文档的BeginDoubleClick事件</p><p>明天有时间慢慢改改看</p>
雪山飞狐_lzh
发表于 2009-5-31 11:12:00
Imports System
Imports System.Collections.Generic
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Namespace TlsTest
Public Class TApplication
Implements IExtensionApplication
Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize
TTest.Start()
End Sub
Public Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate
End Sub
End Class
Public Class TTest
Private Shared m_Veto As Boolean
Private Shared m_AcadDocs As Dictionary(Of IntPtr, AcadDocument) = New Dictionary(Of IntPtr, AcadDocument)
Public Shared Sub Start()
AddHandler Application.DocumentManager.DocumentLockModeChanged, AddressOf vetoCommand
AddHandler Application.DocumentManager.DocumentCreated, AddressOf documentCreated
For Each doc As Document In Application.DocumentManager
Dim acaddoc As AcadDocument = doc.AcadDocument
m_AcadDocs.Add(doc.Window.Handle, acaddoc)
AddHandler acaddoc.BeginDoubleClick, AddressOf beginDoubleClick
Next
End Sub
Shared Sub vetoCommand(ByVal sender As Object, ByVal e As DocumentLockModeChangedEventArgs)
If m_Veto Then
Select Case e.GlobalCommandName.ToLower()
Case "properties"
m_Veto = False
e.Veto()
End Select
End If
End Sub
Shared Sub documentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs)
Dim doc As AcadDocument = e.Document.AcadDocument
m_AcadDocs.Add(e.Document.Window.Handle, doc)
AddHandler doc.BeginDoubleClick, AddressOf beginDoubleClick
End Sub
Shared Sub beginDoubleClick(ByVal PickPoint As Object)
Dim ip As IntPtr = Application.DocumentManager.MdiActiveDocument.Window.Handle
If m_AcadDocs.ContainsKey(ip) Then
Dim doc As AcadDocument = m_AcadDocs(ip)
Dim ss As AcadSelectionSet = doc.PickfirstSelectionSet
If ss.Count = 1 Then
Dim line As AcadLine = ss.Item(0)
If Not (line Is Nothing) Then
Dim xt = Nothing, xd = Nothing
line.GetXData("MyApp", xt, xd)
Application.ShowAlertDialog("数目共" + xd(2).ToString())
m_Veto = True
Return
End If
End If
End If
m_Veto = False
End Sub
End Class
End Namespace
xwjljh
发表于 2009-5-31 23:42:00
<p>谢谢了</p><p>还是遇到问题,我再好好研究研究</p><p>谢谢您的帮助了</p><p></p>
dukeyongwang
发表于 2009-11-3 21:36:00
<p>我在VS2005、CAD2006中测试的效果仍然无法屏蔽属性窗体,应该不是版本的问题吧?</p>
dukeyongwang
发表于 2009-11-3 21:38:00
lzh741206发表于2009-5-30 16:05:00static/image/common/back.gifCom的版本,引用两个类型库using System;using System.Collections.Generic;using Autodesk.AutoCAD.Runtime;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.ApplicationSer
在VS2005和CAD2006中测试的效果还是会显示属性窗体?e.Veto()是什么意思?好像没起到什么作用?
雪山飞狐_lzh
发表于 2009-11-3 21:55:00
<p>原则上2006可以使用NetApi,但最好是不要,Bug很多的</p>
dukeyongwang
发表于 2009-11-3 23:00:00
<p>那在CAD2006中怎么实现实体的双击事件呢?查了很长时间,一直没有解决,有说用反应器的,反应器不是和事件差不多嘛?还有说CUI的,不知道CUI如何实现,忘狐哥和其他大侠们帮帮忙!!!</p>
liminnet
发表于 2009-11-4 17:52:00