- 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
|