用VB.NET实现AUTOCAD中鼠标选中后显示事件
主要用到document中ImpliedSelectionChanged事件
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServicesImports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime
Public Class Class1
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim modalForm As ModalForm = New ModalForm()
<CommandMethod("TestOn")> _
Public Sub MyTestOn()
AddHandler acDoc.ImpliedSelectionChanged, New EventHandler(AddressOf doc_ImpliedSelectionChanged)
End Sub
<CommandMethod("TestOff")> _
Public Sub MyTestOff()
RemoveHandler acDoc.ImpliedSelectionChanged, New EventHandler(AddressOf doc_ImpliedSelectionChanged)
End Sub
Private Sub doc_ImpliedSelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim pkf As PromptSelectionResult = ed.SelectImplied()
If (pkf.Status <> PromptStatus.OK) Then
ed.WriteMessage(vbCrLf & "无选择" & vbCrLf)
Return
End If
Dim objIds() As ObjectId = pkf.Value.GetObjectIds()
ed.WriteMessage(vbCrLf & "选择对象" & objIds.Count & vbCrLf)
End Sub
End Class