Community
Hi, I want to create plug-in that customize most top useful UI, menu command or options to the Ribbon for the Autocad 2014 using vb.net 2010/12
I will share my code provided if you gety it working you share the finished code back here. I am having errors with starting up the app at line 29.
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.Interop Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.Geometry Imports Autodesk.AutoCAD.Customization Imports Autodesk.Windows Namespace RibbonClass Public Class RibbonMake Implements Autodesk.AutoCAD.Runtime.IExtensionApplication Public Sub Initialize() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Initialize ' Create an AutoCAD toolbar with 4 buttons linked to the 4 commands defined below Dim LecModule As System.Reflection.Module = System.Reflection.Assembly.GetExecutingAssembly().GetModules()(0) Dim LecModulePath As String = LecModule.FullyQualifiedName Try LecModulePath = LecModulePath.Substring(0, LecModulePath.LastIndexOf("\")) Catch MsgBox("Error with Module Path") Exit Sub End Try Dim acadApp As Autodesk.AutoCAD.Interop.AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication ''--------this next statement is where I am having problems. AddHandler Application.Idle, AddressOf callback_Idle End Sub Private Sub callback_Idle(ByVal sender As [Object], ByVal e As EventArgs) CreateRibbon() RemoveHandler Application.Idle, AddressOf callback_Idle End Sub Private Sub CreateRibbon() Dim mainAcadRibbon As Autodesk.Windows.RibbonControl = Autodesk.Windows.ComponentManager.Ribbon ' ComponentManager.Ribbon If mainAcadRibbon IsNot Nothing Then Dim rTab As RibbonTab = mainAcadRibbon.FindTab("Tab Name") If rTab IsNot Nothing Then mainAcadRibbon.Tabs.Remove(rTab) End If rTab = New RibbonTab() rTab.Title = "Title" rTab.Id = "ID" mainAcadRibbon.Tabs.Add(rTab) addPanelsToRibbon(rTab) End If End Sub Private Shared Sub addPanelsToRibbon(ByVal rtab As RibbonTab) rtab.Panels.Add(panelExample()) End Sub Private Shared Function panelExample() As RibbonPanel Dim rb1 As Autodesk.Windows.RibbonButton Dim rb2 As Autodesk.Windows.RibbonButton Dim rps As New Autodesk.Windows.RibbonPanelSource() rps.Title = "Title" Dim rp As New RibbonPanel() rp.Source = rps rb1 = New Autodesk.Windows.RibbonButton() rb1.Name = "Name1" rb1.ShowText = True rb1.Text = "Text1" rb1.CommandHandler = New RibbonCommandHandler() rps.Items.Add(rb1) rb2 = New Autodesk.Windows.RibbonButton() rb2.Name = "Name2" rb2.ShowText = True rb2.Text = "Text2" rb2.CommandHandler = New RibbonCommandHandler() rps.Items.Add(rb2) Return rp End Function Public Class RibbonCommandHandler 'Implements System.Windows.Input.ICommand Public Function CanExecute(ByVal parameter As Object) As Boolean Return True End Function ' CanExecuteChanged must be implemented, even if not used. Public Event CanExecuteChanged As EventHandler Public Sub Execute(ByVal parameter As Object) Dim doc As Document = Application.DocumentManager.MdiActiveDocument If TypeOf parameter Is Autodesk.Windows.RibbonButton Then Dim button As Autodesk.Windows.RibbonButton = TryCast(parameter, Autodesk.Windows.RibbonButton) Try Select Case button.Name.ToString() Case "Name1" Exit Select Case "Name2" Exit Select Case Else Exit Select End Select Catch ex As Autodesk.AutoCAD.Runtime.Exception Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString()) Catch ex As System.NullReferenceException Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString()) End Try End If End Sub End Class Private Sub Terminate() Implements Autodesk.AutoCAD.Runtime.IExtensionApplication.Terminate End Sub End Class End Namespace