Imports System.Drawing
Imports System.Windows.Input
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.Windows
' This line is not mandatory, but improves loading performances
<Assembly: ExtensionApplication(GetType(CData.MyPlugin))>
Namespace CData
Public Class MyPlugin
Implements IExtensionApplication
Public Sub Initialize() Implements IExtensionApplication.Initialize
Dim ribCntrl As RibbonControl = Autodesk.Windows.ComponentManager.Ribbon
Dim ribTab As RibbonTab
For i = 0 To ribCntrl.Tabs.Count - 1
If ribCntrl.Tabs.Item(i).Title = "TRex" Then
ribTab = ribCntrl.Tabs.Item(i)
Exit For
End If
Next
' проверяю если уже есть панель, то обращаюсь к ней, если нет то создаю новую
If IsNothing(ribTab) = True Then
ribTab = New RibbonTab()
ribTab.Title = "TRex"
ribTab.Id = "RibbonExample_ID"
ribCntrl.Tabs.Add(ribTab)
End If
Dim ribSourcePanel As RibbonPanelSource = New RibbonPanelSource
ribSourcePanel.Title = "Элементы сети"
Dim ribPanel As RibbonPanel = New RibbonPanel
ribPanel.Source = ribSourcePanel
ribTab.Panels.Add(ribPanel)
' кнопка RenStrPlan переименовать колодец на плане
Dim tRenStrPlan As New RibbonToolTip
tRenStrPlan.IsHelpEnabled = False
Dim ribBtnRenStrPlan As New RibbonButton
ribBtnRenStrPlan.CommandParameter = "RenStrPlan"
tRenStrPlan.Command = "RenStrPlan"
ribBtnRenStrPlan.Name = "rbtnRenStrPlan"
ribBtnRenStrPlan.Text = "Rename" & vbLf & "Struct"
tRenStrPlan.Title = "RenStrPlan"
ribBtnRenStrPlan.CommandHandler = New RibbonCommandHandler()
ribBtnRenStrPlan.Orientation = Windows.Controls.Orientation.Vertical
ribBtnRenStrPlan.Size = RibbonItemSize.Large
' преобразование картинки по пути в изображение
Dim btmRenStrPlan As New Bitmap(My.Application.Info.DirectoryPath & "\Icon\cdata.png")
ribBtnRenStrPlan.LargeImage = CModul.BitmapToImage(btmRenStrPlan)
ribBtnRenStrPlan.ShowImage = True
ribBtnRenStrPlan.ShowText = True
tRenStrPlan.Content = "Переименовать колодец на плане"
ribBtnRenStrPlan.ToolTip = tRenStrPlan
ribSourcePanel.Items.Add(ribBtnRenStrPlan)
ribSourcePanel.Items.Add(New RibbonSeparator)
End Sub
Public Sub Terminate() Implements IExtensionApplication.Terminate
' Do plug-in application clean up here
End Sub
End Class
Public Class RibbonCommandHandler
Implements System.Windows.Input.ICommand
Public Function CanExecute(parameter As Object) As Boolean
Return True
End Function
Public Event CanExecuteChanged As EventHandler
Private Event ICommand_CanExecuteChanged As EventHandler Implements ICommand.CanExecuteChanged
Public Sub Execute(parameter As Object)
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
If TypeOf parameter Is RibbonButton Then
Dim button As RibbonButton = TryCast(parameter, RibbonButton)
doc.Editor.WriteMessage(vbLf & "RibbonButton Executed: " + button.Text + vbLf)
End If
End Sub
Private Function ICommand_CanExecute(parameter As Object) As Boolean Implements ICommand.CanExecute
Return True
End Function
Private Sub ICommand_Execute(parameter As Object) Implements ICommand.Execute
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
If TypeOf parameter Is RibbonButton Then
Dim button As RibbonButton = TryCast(parameter, RibbonButton)
Application.DocumentManager.MdiActiveDocument.SendStringToExecute(button.CommandParameter & " ", True, False, True)
End If
End Sub
End Class
End Namespace