Hi everybody
I have created a custom ribbon in vb.net. And it works now.
However. To make it work i had to do a workaround because IExtensionApplication.Initialize is apparently run before the Ribbon is created in AutoCAD. To make it work i created a time that runs until the ribbon is created.
But i think this is implementation is flawed since i had to do the workaround, but also because the ribbon disappearse when the ribbon is updated. Say when the user changes something in the CUI menu. I haven't been able to find any solution to this issue on the forum or on the web in general. Does anyone have an idea what i'm doing wrong?
Partial Public Class BenteMenu Implements IExtensionApplication Dim WithEvents WSARibPanel As RibbonPanel Dim WithEvents ReformerRibPanel As RibbonPanel Dim WithEvents CNVPanel As RibbonPanel Dim WithEvents ModelPanel As RibbonPanel Dim WithEvents LayoutPanel As RibbonPanel Private WithEvents ribbonTimer As New Timer() Private WithEvents thsdwg As AcadDocument Private WithEvents docs As DocumentCollection Public Sub Initialize() Implements IExtensionApplication.Initialize If Threading.Thread.CurrentThread.CurrentCulture.ToString <> "en-GB" Then Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB", False) End If HTEventLog.InitLog("AutoCAD Tools") ThisDwg.InitNow() docs = Application.DocumentManager acadApp = Application.AcadApplication() thsdwg = Application.AcadApplication.ActiveDocument ThisDrawing = Application.AcadApplication.ActiveDocument ribbonTimer.Interval = 2000 ribbonTimer.Start() End Sub Public Sub Terminate() Implements IExtensionApplication.Terminate End Sub Private Function getBmpImage(ByVal imageName As String) As BitmapImage Try Dim bImg As New BitmapImage(New System.Uri(strIconPath & imageName)) Return bImg Catch LogError("Icon Not Found: " & imageName) End Try Return Nothing End Function Private Sub CreateLayoutPanel(ByVal BenteTab As RibbonTab) If BenteTab Is Nothing Then Return Dim ribSourcePanel As New RibbonPanelSource() ribSourcePanel.Title = "Paper Bente" 'now the panel LayoutPanel = New RibbonPanel() LayoutPanel.Source = ribSourcePanel BenteTab.Panels.Add(LayoutPanel) ' Creating Contents LayoutPanel.IsVisible = My.Settings.PaperBenteVisible End Sub Private Sub CreateModelPanel(ByVal BenteTab As RibbonTab) If BenteTab Is Nothing Then Return Dim ribSourcePanel As New RibbonPanelSource() ribSourcePanel.Title = "Model Bente" 'now the panel ModelPanel = New RibbonPanel() ModelPanel.Source = ribSourcePanel BenteTab.Panels.Add(ModelPanel) ' Creating content ModelPanel.IsVisible = My.Settings.ModelBenteVisible End Sub Private Sub CreateCNVPanel(ByVal BenteTab As RibbonTab) If BenteTab Is Nothing Then Return Dim ribSourcePanel As New RibbonPanelSource() ribSourcePanel.Title = "Converter Bente" 'now the panel CNVPanel = New RibbonPanel() CNVPanel.Source = ribSourcePanel BenteTab.Panels.Add(CNVPanel) 'Creating Content CNVPanel.IsVisible = My.Settings.ConverterBenteVisible End Sub Private Sub CreateWSAPanel(ByVal BenteTab As RibbonTab) If BenteTab Is Nothing Then Return Dim ribSourcePanel As New RibbonPanelSource() ribSourcePanel.Title = "WSA Bente" 'now the panel WSARibPanel = New RibbonPanel() WSARibPanel.Source = ribSourcePanel BenteTab.Panels.Add(WSARibPanel) 'creating contents WSARibPanel.IsVisible = My.Settings.WSABenteVisible End Sub Private Sub CreateReformerPanel(ByVal BenteTab As RibbonTab) If BenteTab Is Nothing Then Return Dim ribSourcePanel As New RibbonPanelSource() ribSourcePanel.Title = "Reformer Bente" 'now the panel ReformerRibPanel = New RibbonPanel() ReformerRibPanel.Source = ribSourcePanel BenteTab.Panels.Add(ReformerRibPanel) 'Creating contents ReformerRibPanel.IsVisible = My.Settings.ReformerBenteVisible End Sub Private Function CreateButton(ByVal text As String, ByVal CommandParameter As String, ByVal showtext As Boolean, ByVal showImage As Boolean, ByVal smallImage As BitmapImage, ByVal largeImage As BitmapImage, ByVal orientation As System.Windows.Controls.Orientation, ByVal size As Autodesk.Windows.RibbonItemSize) Try Dim ribbonbutton1 As New RibbonButton() ribbonbutton1.Text = text ribbonbutton1.CommandParameter = CommandParameter ribbonbutton1.ShowText = showtext ribbonbutton1.ShowImage = showImage If showImage Then If size = RibbonItemSize.Standard Then If Not smallImage Is Nothing Then ribbonbutton1.Image = smallImage Else If Not largeImage Is Nothing Then ribbonbutton1.LargeImage = largeImage End If End If ribbonbutton1.Orientation = orientation ribbonbutton1.Size = size ribbonbutton1.CommandHandler = New AdskCommandHandler() Return ribbonbutton1 Catch ex As System.Exception LogError(text & " Button failed", ex) Return Nothing End Try End Function Private Sub CreateRibbon() Handles ribbonTimer.Tick Dim ribCntrl As RibbonControl Dim BenteTab As RibbonTab = Nothing ribCntrl = ComponentManager.Ribbon If ribCntrl Is Nothing Then Return SendMessage("Creating Bente") ribbonTimer.Stop() ribbonTimer = Nothing If BenteTab Is Nothing Then For i As Integer = 0 To ribCntrl.Tabs.Count - 1 If ribCntrl.Tabs(i).Title = "Bente 2.0" Then BenteTab = ribCntrl.Tabs(i) End If Next Else If Not ribCntrl.Tabs.Contains(BenteTab) Then ribCntrl.Tabs.Insert(3, BenteTab) End If End If 'add the tab If BenteTab Is Nothing Then BenteTab = New RibbonTab() BenteTab.Title = "Bente 2.0" BenteTab.Id = "BenteTab" ribCntrl.Tabs.Insert(3, BenteTab) End If If BenteTab.Panels.Count = 0 Then CreateLayoutPanel(BenteTab) CreateModelPanel(BenteTab) CreateWSAPanel(BenteTab) CreateCNVPanel(BenteTab) CreateReformerPanel(BenteTab) End If End Sub
Best regards Magnus
Hi magnus,
I know for a fact when u user changes his workspace the ribbon wil disapear. I think when a user changes his cui file the same principle goes.
Please look at this example this handles the ribbon load IExtensionApllication and when a user changes his workspace.
http://forums.autodesk.com/t5/NET/RibbonTab-in-all-Workspaces/td-p/2853958
Kind regards,
Irvin
Hi Irvin
It doesn't work when you change something in the CUI menu. Otherwise it works fine. Have you had this experience?
br Magnus
Hi there ik think you should reload your ribbon like in the example only now ik think you should use the commandended event.
pseudo code:
if(command cui) ended
reload ribbon
I dont know if there is a AutoCAD variable wich can indicate if the cui file has changed. But i think you should look at the commandended event.
Kind regards
Irvin
Hi Irvin
This strikes me as a poor solution since listening to the CommandEnded event would have my program triggered everytime a command is ended, making my program slow down AutoCAD.
Is there really no official solution from Autodesk to this problem?
br Magnus
I don't think it's a poor solution. For that mater you also use en event that checks a variable has changed. In this case when the user changes it workspace. Your ribbon wil be reloaded.
Of you look ad event's autodesk does not recommend to use transactionhandling within events. So you use the commandended event to do that kind of work.
I don't think this wil have much impact on performance. Because you only need to check
if (commandended != cui) return;
I don't have an other solution for you.
I use commandended alot but have no performance issues.
irvin
Can't find what you're looking for? Ask the community or share your knowledge.