Ok so I've made a ribbon bar in .net. It contains a few thousand buttons in it to make my job easier to do. Though sometimes autocad doesn't start up correctly and I have to switch to a different workspace it wipes out the ribbon bar addon I created.
Rather annoying and the steps to get around the issue is just takes to long, and complicated as I want to populate this to the rest of the deparment without them worrying about it.
With that being said here is some of the code from it. Written in .net 4.0. I know originally there was some handle way to force it up but never got it to work or never showed up. So anyone can you help me with my issue? I know it was located in the topside of the code so its located in this portion of it to force the fill to refresh.
Imports System.Drawing Imports System.Drawing.Imaging Imports System.IO Imports System.Runtime.InteropServices Imports System.Windows.Media.Imaging Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.Windows Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Runtime Imports cadApp = Autodesk.AutoCAD.ApplicationServices.Application Imports cadAppSrvs = Autodesk.AutoCAD.ApplicationServices Public Class ConveyorRibbonBar Implements IExtensionApplication Public Shared BlockName As String Overridable Sub Initialize() Implements IExtensionApplication.Initialize If Autodesk.Windows.ComponentManager.Ribbon Is Nothing Then 'load the custom Ribbon on startup, but at this point 'the Ribbon control is not available, so register for 'an event and wait AddHandler Autodesk.Windows.ComponentManager.ItemInitialized, AddressOf ComponentManager_ItemInitialized Else 'the assembly was loaded using NETLOAD, so the ribbon 'is available and we just create the ribbon createRibbon() End If End Sub Overridable Sub Terminate() Implements IExtensionApplication.Terminate End Sub Private Sub ComponentManager_ItemInitialized(ByVal sender As Object, ByVal e As RibbonItemEventArgs) 'now one Ribbon item is initialized, but the Ribbon control 'may not be available yet, so check if before If Autodesk.Windows.ComponentManager.Ribbon IsNot Nothing Then 'ok, create Ribbon createRibbon() 'and remove the event handler RemoveHandler Autodesk.Windows.ComponentManager.ItemInitialized, AddressOf ComponentManager_ItemInitialized End If End Sub 'Creates the Ribbon Tabs Public Sub createRibbon() Dim ribCntrl As Autodesk.Windows.RibbonControl = Autodesk.Windows.ComponentManager.Ribbon If ComponentManager.Ribbon Is Nothing Then Return End If For i As Integer = 0 To ribCntrl.Tabs.Count - 1 If ribCntrl.Tabs(i).Id.Equals("My_Rib_ID") Then Return End If Next 'Creates a tab Dim mbc1Tab As New RibbonTab() mbc1Tab.Title = "Mattop BC 1-14" mbc1Tab.Id = "Mattop_BC_1_14" ribCntrl.Tabs.Add(mbc1Tab) Dim mbc2Tab As New RibbonTab() mbc2Tab.Title = "Mattop BC 16-20 & Options" mbc2Tab.Id = "Mattop_BC_16_20_Options" ribCntrl.Tabs.Add(mbc2Tab) Dim ssbc1Tab As New RibbonTab() ssbc1Tab.Title = "SS BC 1-10" ssbc1Tab.Id = "SS_BC_1-10" ribCntrl.Tabs.Add(ssbc1Tab) Dim ssbc2Tab As New RibbonTab() ssbc2Tab.Title = "SS BC 12-20 & Options" ssbc2Tab.Id = "SS_BC_12_20_Options" ribCntrl.Tabs.Add(ssbc2Tab) Dim nrcc1Tab As New RibbonTab() nrcc1Tab.Title = "Case Conveyor 1" nrcc1Tab.Id = "Case_Conveyor_1" ribCntrl.Tabs.Add(nrcc1Tab) Dim pcr1Tab As New RibbonTab() pcr1Tab.Title = "Pallet Conveyor" pcr1Tab.Id = "Pallet_Conveyor" ribCntrl.Tabs.Add(pcr1Tab) 'Add the panels to the created tabs 'Bottle Conveyor Mattop 1-14 addmbc1c(mbc1Tab) addmbc2c(mbc1Tab) addmbc3c(mbc1Tab) addmbc4c(mbc1Tab) addmbc5c(mbc1Tab) addmbc6c(mbc1Tab) addmbc7c(mbc1Tab) addmbc8c(mbc1Tab) addmbc10c(mbc1Tab) addmbc12c(mbc1Tab) addmbc14c(mbc1Tab) 'Bottle Conveyor Mattop 16-20 & Other Items addmbc16c(mbc2Tab) addmbc18c(mbc2Tab) addmbc20c(mbc2Tab) addmbcFM(mbc2Tab) addmbcclean(mbc2Tab) addmbcDischarge(mbc2Tab) addInliners(mbc2Tab) addmbcAccum(mbc2Tab) addmbcWF(mbc2Tab) 'Stainless Steel Bottle Conveyor 1-14 addssbc1c(ssbc1Tab) addssbc2c(ssbc1Tab) addssbc3c(ssbc1Tab) addssbc4c(ssbc1Tab) addssbc5c(ssbc1Tab) addssbc6c(ssbc1Tab) addssbc7c(ssbc1Tab) addssbc8c(ssbc1Tab) addssbc10c(ssbc1Tab) 'Stainless Steel Bottle Conveyor 16-20 & Other Items addssbc12c(ssbc2Tab) addssbc14c(ssbc2Tab) addssbc16c(ssbc2Tab) addssbc18c(ssbc2Tab) addssbc20c(ssbc2Tab) addssbcDischarge(ssbc2Tab) addssbcAccum(ssbc2Tab) addSSInliners(ssbc2Tab) 'Non Returnable Case Conveyors addnrccurves(nrcc1Tab) addnrccurves2(nrcc1Tab) 'Pallet Conveyors addpcrroller950(pcr1Tab) addpcrroller1150(pcr1Tab) addpcrroller1350(pcr1Tab) addpcrroller950do(pcr1Tab) addpcrroller1150do(pcr1Tab) addpcrroller1350do(pcr1Tab) addpcrchain(pcr1Tab) addpcrturners(pcr1Tab) addpcrcarriage(pcr1Tab) addpcraccess(pcr1Tab) 'Set as active tab (deactivated currently to default to Home Tab) 'mbc1Tab.IsActive = True End Sub Private Sub removeRibbon() Dim ribCntrl As Autodesk.Windows.RibbonControl = Autodesk.Windows.ComponentManager.Ribbon 'find the custom tab using the Id For i As Integer = 0 To ribCntrl.Tabs.Count - 1 If ribCntrl.Tabs(i).Id.Equals("Mattop_Bottle_Conveyor") Then ribCntrl.Tabs.Remove(ribCntrl.Tabs(i)) Return End If Next End Sub
The ribbon api is not persistant. In other words if you make changes to the cui or change your workspace then your ribbon will dissapear. Your best bet is to monitor the CUI or the QUICKCUI commands and if they have been run then reinitiate your ribbon control. You can do the same thing with the workspace by just monitoring the WSCURRENT system variable.
You can read a blog post by autodesk on the subject here