.NET

Reply
Active Contributor
mamj
Posts: 36
Registered: ‎05-31-2007
Message 1 of 7 (551 Views)

Ribbon that disappears

551 Views, 6 Replies
05-13-2011 01:31 AM

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

 

Distinguished Contributor
Irvin
Posts: 112
Registered: ‎04-22-2009
Message 2 of 7 (535 Views)

Re: Ribbon that disappears

05-13-2011 04:10 AM in reply to: mamj

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

Active Contributor
mamj
Posts: 36
Registered: ‎05-31-2007
Message 3 of 7 (497 Views)

Re: Ribbon that disappears

05-23-2011 05:21 AM in reply to: 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

Distinguished Contributor
Irvin
Posts: 112
Registered: ‎04-22-2009
Message 4 of 7 (494 Views)

Re: Ribbon that disappears

05-23-2011 05:31 AM in reply to: mamj

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

Active Contributor
mamj
Posts: 36
Registered: ‎05-31-2007
Message 5 of 7 (474 Views)

Re: Ribbon that disappears

05-30-2011 06:16 AM in reply to: 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

Distinguished Contributor
Irvin
Posts: 112
Registered: ‎04-22-2009
Message 6 of 7 (471 Views)

Re: Ribbon that disappears

05-30-2011 06:34 AM in reply to: mamj

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

Active Contributor
mamj
Posts: 36
Registered: ‎05-31-2007
Message 7 of 7 (468 Views)

Re: Ribbon that disappears

05-30-2011 06:41 AM in reply to: mamj

ok.. I will try it then.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community