空白右键菜单
Imports System
Imports Autodesk.AutoCAD.Windows
Imports Autodesk.AutoCAD.Runtime
<Assembly: CommandClass(GetType(Contextmenu.Contextmenu))>
Namespace Contextmenu
Public Class Contextmenu
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Private contextMenu As ContextMenuExtension
'初始化菜单
Public Sub Initialize() Implements IExtensionApplication.Initialize
AddMenu()
End Sub
'移除菜单
Public Sub Terminate() Implements IExtensionApplication.Terminate
Remove()
End Sub
'添加菜单
Public Sub AddMenu()
Try
contextMenu = New ContextMenuExtension()
contextMenu.Title = "添加右键菜单测试_Title"
Dim MenuItem As Autodesk.AutoCAD.Windows.MenuItem
MenuItem = New Autodesk.AutoCAD.Windows.MenuItem("添加右键菜单测试")
AddHandler MenuItem.Click, AddressOf CallbackOnClick
contextMenu.MenuItems.Add(MenuItem)
Autodesk.AutoCAD.ApplicationServices.Application.AddDefaultContextMenuExtension(contextMenu)
Catch ex As system.exception
MsgBox(ex.ToString)
End Try
End Sub
'移除菜单
Public Sub Remove()
Try
If contextMenu IsNot Nothing Then
Autodesk.AutoCAD.ApplicationServices.Application.RemoveDefaultContextMenuExtension(contextMenu)
End If
Catch ex As System.Exception
MsgBox(ex.ToString)
End Try
End Sub
'菜单事件
Public Sub CallbackOnClick(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("添加右键菜单测试")
End Sub
End Class
End Namespace
Imports Autodesk.AutoCAD.Windows
Imports Autodesk.AutoCAD.Runtime
<Assembly: CommandClass(GetType(Contextmenu.Contextmenu))>
Namespace Contextmenu
Public Class Contextmenu
Implements Autodesk.AutoCAD.Runtime.IExtensionApplication
Private contextMenu As ContextMenuExtension
'初始化菜单
Public Sub Initialize() Implements IExtensionApplication.Initialize
AddMenu()
End Sub
'移除菜单
Public Sub Terminate() Implements IExtensionApplication.Terminate
Remove()
End Sub
'添加菜单
Public Sub AddMenu()
Try
contextMenu = New ContextMenuExtension()
contextMenu.Title = "添加右键菜单测试_Title"
Dim MenuItem As Autodesk.AutoCAD.Windows.MenuItem
MenuItem = New Autodesk.AutoCAD.Windows.MenuItem("添加右键菜单测试")
AddHandler MenuItem.Click, AddressOf CallbackOnClick
contextMenu.MenuItems.Add(MenuItem)
Autodesk.AutoCAD.ApplicationServices.Application.AddDefaultContextMenuExtension(contextMenu)
Catch ex As system.exception
MsgBox(ex.ToString)
End Try
End Sub
'移除菜单
Public Sub Remove()
Try
If contextMenu IsNot Nothing Then
Autodesk.AutoCAD.ApplicationServices.Application.RemoveDefaultContextMenuExtension(contextMenu)
End If
Catch ex As System.Exception
MsgBox(ex.ToString)
End Try
End Sub
'菜单事件
Public Sub CallbackOnClick(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("添加右键菜单测试")
End Sub
End Class
End Namespace
选择对象右键菜单
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Windows
Imports System
Namespace ContextMenuApplication
Public Class Commands
Implements IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
CountMenu.Attach()
End Sub
Public Sub Terminate() Implements IExtensionApplication.Terminate
CountMenu.Detach()
End Sub
<CommandMethod("COUNT", CommandFlags.UsePickSet)> _
Public Shared Sub CountSelection()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim psr As PromptSelectionResult = ed.GetSelection()
If psr.Status = PromptStatus.OK Then
ed.WriteMessage(vbLf & "Selected {0} entities.", psr.Value.Count)
End If
End Sub
End Class
Public Class CountMenu
Private Shared cme As ContextMenuExtension
Public Shared Sub Attach()
cme = New ContextMenuExtension()
Dim mi As New MenuItem("Count")
AddHandler mi.Click, AddressOf OnCount
cme.MenuItems.Add(mi)
Dim rxc As RXClass = Entity.GetClass(GetType(Entity))
Application.AddObjectContextMenuExtension(rxc, cme)
End Sub
Public Shared Sub Detach()
Dim rxc As RXClass = Entity.GetClass(GetType(Entity))
Application.RemoveObjectContextMenuExtension(rxc, cme)
End Sub
Private Shared Sub OnCount(ByVal o As [Object], ByVal e As EventArgs)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
doc.SendStringToExecute("_.COUNT ", True, False, False)
End Sub
End Class
End Namespace
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Windows
Imports System
Namespace ContextMenuApplication
Public Class Commands
Implements IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
CountMenu.Attach()
End Sub
Public Sub Terminate() Implements IExtensionApplication.Terminate
CountMenu.Detach()
End Sub
<CommandMethod("COUNT", CommandFlags.UsePickSet)> _
Public Shared Sub CountSelection()
Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim psr As PromptSelectionResult = ed.GetSelection()
If psr.Status = PromptStatus.OK Then
ed.WriteMessage(vbLf & "Selected {0} entities.", psr.Value.Count)
End If
End Sub
End Class
Public Class CountMenu
Private Shared cme As ContextMenuExtension
Public Shared Sub Attach()
cme = New ContextMenuExtension()
Dim mi As New MenuItem("Count")
AddHandler mi.Click, AddressOf OnCount
cme.MenuItems.Add(mi)
Dim rxc As RXClass = Entity.GetClass(GetType(Entity))
Application.AddObjectContextMenuExtension(rxc, cme)
End Sub
Public Shared Sub Detach()
Dim rxc As RXClass = Entity.GetClass(GetType(Entity))
Application.RemoveObjectContextMenuExtension(rxc, cme)
End Sub
Private Shared Sub OnCount(ByVal o As [Object], ByVal e As EventArgs)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
doc.SendStringToExecute("_.COUNT ", True, False, False)
End Sub
End Class
End Namespace
[本日志由 tiancao1001 于 2018-09-14 10:43 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |