.NET

.NET

Reply
Active Member
imvivs
Posts: 6
Registered: ‎09-11-2013
Message 1 of 2 (550 Views)

How to Customize top level UI to Ribbons using VB.NET for AUTOCAD 2014

550 Views, 1 Replies
09-11-2013 11:26 AM

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

Valued Contributor
jaboone
Posts: 91
Registered: ‎12-05-2011
Message 2 of 2 (535 Views)

Re: How to Customize top level UI to Ribbons using VB.NET for AUTOCAD 2014

09-11-2013 02:54 PM in reply to: imvivs

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

 

Learning as I go
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.