Message 1 of 7
Ribbon that disappears
Not applicable
05-13-2011
01:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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