.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using Search When Progrmatically Created Ribbon Tab Is In Place Causes Crash

2 REPLIES 2
Reply
Message 1 of 3
kbrown
1013 Views, 2 Replies

Using Search When Progrmatically Created Ribbon Tab Is In Place Causes Crash

I have an issue which is reproducible in AutoCAD 2014 (have not tested in other versions). When the drawing search feature (click Icon Button at top left, use search text box at top) is executed when my progrmatically created Ribbon Tab is in place, AutoCAD crashes with the following error:

 

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at Autodesk.AutoCAD.Internal.Windows.SearchUtil.ContainAnyKeywordInTooltip(RibbonItem item, List`1 searchRecords)
   at Autodesk.AutoCAD.Internal.Windows.SearchUtil.SearchTextFromItem(RibbonItem item, SearchRecords searchRecords)
   at Autodesk.AutoCAD.Internal.Windows.SearchUtil.SearchCommandItem(RibbonCommandItem cmdItem, SearchRecords searchRecords, List`1 bestMatches, List`1 normalMatches, List`1 relativeMatches, String itemPath, String groupName)
   at Autodesk.AutoCAD.Internal.Windows.SearchUtil.SearchItems(RibbonItemCollection items, SearchRecords searchRecords, ISearchResults feedback, List`1 bestMatches, List`1 normalMatches, List`1 relativeMatches, String itemPath, String groupName)
   at Autodesk.AutoCAD.Internal.Windows.SearchContent.SearchInRibbon(SearchRecords searchRecords, ISearchResults feedback, List`1 bestMatches, List`1 normalMatches, List`1 relativeMatches)
   at Autodesk.AutoCAD.Internal.Windows.SearchContent.Search(String searchText, ISearchResults feedback)
   at Autodesk.Private.Windows.SearchWorker.Search()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

 

Looking at the top of the call stack, I am left wondering if the problem is that I have set a tooltip to null. Why this should cause AutoCAD to completely crash is beyond me. A simple check for null would prevent the error. Maybe I don't comprehend something going on here.

 

Here is the source for a class responsible for creating the ribbon tab for my plugin and populating it with controls. Some of the code dynamically creates ribbon items based on data stored in a database, so it is not possible to provide working code, unfortunately.

 

I've tried setting the tooltips of some items to string.empty instead of null where i thought they might be null. But I'm wondering if this is even the problem at all. Any insights would be much appreciated.

 

Public Class ACADRibbonFactory
    Public Shared Function BuildACADRibbon(ByVal RibbonData As DataSet) As ACADRibbonManager
        If RibbonData Is Nothing Then Throw New ArgumentNullException("RibbonData")
        Dim ribbonTabs As New List(Of ACADRibbonTab)
        Dim manager As New ACADRibbonManager(ribbonTabs, RibbonData.Tables("AutoCAD_Ribbon_Panel_Conveyor_Type"))
        For Each tabRow As DataRow In RibbonData.Tables("AutoCAD_Ribbon_Tab").Select("", "Position")
            Dim acadTabObject As New RibbonTab()
            acadTabObject.Title = tabRow("Title").ToString()
            acadTabObject.Tag = tabRow("ID").ToString()
            acadTabObject.Id = tabRow("ID").ToString()
            Dim tab As New ACADRibbonTab(Convert.ToInt32(tabRow("ID")), tabRow("Title").ToString(), Convert.ToInt32(tabRow("Position")), acadTabObject)
            For Each panelRow As DataRow In RibbonData.Tables("AutoCAD_Ribbon_Panel").Select("AutoCAD_Ribbon_Tab_ID = " + tab.ID.ToString(), "Position")
                Dim acadPanelObject As New RibbonPanel()
                Dim acadPanelSourceObject As New RibbonPanelSource()
                With acadPanelSourceObject
                    .Title = panelRow("Title").ToString()
                    .Tag = panelRow("ID").ToString()
                    .Id = panelRow("ID").ToString()
                End With
                acadPanelObject.Source = acadPanelSourceObject
                Dim panel As New ACADRibbonPanel(Convert.ToInt32(panelRow("ID")), panelRow("Title").ToString(), Convert.ToInt32(panelRow("Position")), tab, acadPanelObject)
                If Not panelRow.IsNull("Static_Alias") AndAlso panelRow("Static_Alias") = "NiC" Then
                    acadPanelSourceObject.Id = ACAD_RIBBON_NIC_PANEL_ID
                    'build Row 1 of Nic Panel
                    Dim nicRibbonRow1 As New RibbonRowPanel()
                    nicRibbonRow1.Id = ACAD_RIBBON_NIC_ROW1_ID
                    BuildNiCRibbonPanelRow1(manager, nicRibbonRow1)
                    acadPanelSourceObject.Items.Add(nicRibbonRow1)
                    acadPanelSourceObject.Items.Add(New RibbonRowBreak())
                    'build Row 2 of Nic Panel
                    Dim nicRibbonRow2 As New RibbonRowPanel()
                    nicRibbonRow2.Id = ACAD_RIBBON_NIC_ROW2_ID
                    BuildNiCRibbonPanelRow2(manager, nicRibbonRow2)
                    acadPanelSourceObject.Items.Add(nicRibbonRow2)
                    acadPanelSourceObject.Items.Add(New RibbonRowBreak())
                    'build Row 3 of Nic Panel
                    Dim nicRibbonRow3 As New RibbonRowPanel()
                    nicRibbonRow3.Id = ACAD_RIBBON_NIC_ROW3_ID
                    BuildNiCRibbonPanelRow3(manager, nicRibbonRow3)
                    acadPanelSourceObject.Items.Add(nicRibbonRow3)
                    acadPanelSourceObject.Items.Add(New RibbonRowBreak())
                Else
                    For Each rowRow As DataRow In RibbonData.Tables("AutoCAD_Ribbon_Panel_Row").Select("AutoCAD_Ribbon_Panel_ID = " + panel.ID.ToString(), "Position")
                        Dim acadRowObject As New RibbonRowPanel()
                        acadRowObject.Id = rowRow("ID").ToString()
                        Dim row As New ACADRibbonPanelRow(Convert.ToInt32(rowRow("ID")), rowRow("Name").ToString(), Convert.ToInt32(rowRow("Position")), panel, acadRowObject)
                        For Each itemRow As DataRow In RibbonData.Tables("AutoCAD_Ribbon_Item").Select("AutoCAD_Ribbon_Panel_Row_ID = " + row.ID.ToString(), "Position")
                            Dim itemTypeID As Integer = Convert.ToInt32(itemRow("AutoCAD_Ribbon_Item_Type_ID"))
                            Dim itemID As Integer = itemRow("ID")
                            Dim itemName As String = itemRow("Name")
                            Dim itemGUID As String = Guid.NewGuid().ToString()
                            Dim itemText As String = IIf(itemRow.IsNull("Text"), String.Empty, itemRow("Text"))
                            Dim itemDescription As String = IIf(itemRow.IsNull("Description"), String.Empty, itemRow("Description"))
                            Dim itemPositoin As Integer = Convert.ToInt32(itemRow("Position"))
                            Dim itemShowText As Boolean = itemRow("Show_Text")
                            Dim itemShowImage As Boolean = itemRow("Show_Image")
                            Dim itemSmallImage As Bitmap = Nothing
                            If Not itemRow.IsNull("Small_Image") Then
                                Using ms As New MemoryStream(DirectCast(itemRow("Small_Image"), Byte()))
                                    itemSmallImage = New Bitmap(ms)
                                End Using
                            End If
                            Dim itemLargeImage As Bitmap = Nothing
                            If Not itemRow.IsNull("Large_Image") Then
                                Using ms As New MemoryStream(DirectCast(itemRow("Large_Image"), Byte()))
                                    itemLargeImage = New Bitmap(ms)
                                End Using
                            End If
                            Dim itemEnabled As Boolean = itemRow("Enabled")
                            Dim itemVisible As Boolean = itemRow("Visible")
                            Dim itemActions As New List(Of ACADRibbonItemAction)
                            For Each actionRow As DataRow In (From n In RibbonData.Tables("AutoCAD_Ribbon_Item_Action") Where n("AutoCAD_Ribbon_Item_ID") = itemID Select n Order By Convert.ToInt32(n("Position")))
                                Dim actionTypeID As Integer = actionRow("AutoCAD_Ribbon_Item_Action_Type_ID")
                                Select Case actionTypeID
                                    Case WF_RIBBON_ACTION_TYPE_ID
                                        itemActions.Add(New ACADRibbonItemAction(RibbonObjectType.Item, RibbonItemActionType.RunWorkflow, Convert.ToInt32(actionRow("Position")), actionRow("Action_Data").ToString()))
                                    Case ACCESSORY_RIBBON_ACTION_TYPE_ID
                                        itemActions.Add(New ACADRibbonItemAction(RibbonObjectType.Item, RibbonItemActionType.AddAccessory, Convert.ToInt32(actionRow("Position")), actionRow("Action_Data").ToString()))
                                    Case SHOW_FACTORY_CATEGORY_RIBBON_ACTION_TYPE_ID
                                        itemActions.Add(New ACADRibbonItemAction(RibbonObjectType.Item, RibbonItemActionType.ShowFactoryCategory, Convert.ToInt32(actionRow("Position")), actionRow("Action_Data").ToString()))
                                    Case Else
                                        Throw New NotSupportedException("AutoCAD_Ribbon_Item_Action_Type_ID invalid where AutoCAD_Ribbon_Item_Action_ID = " + actionRow("ID").ToString())
                                End Select
                            Next
                            Select Case itemTypeID
                                Case 1
                                    'Ribbon Button
                                    Dim acadButtonObject As New RibbonButton()
                                    acadButtonObject.Name = itemName
                                    acadButtonObject.Id = itemGUID
                                    acadButtonObject.Tag = itemID
                                    acadButtonObject.ShowImage = itemShowImage
                                    acadButtonObject.ShowText = itemShowText
                                    If itemSmallImage IsNot Nothing Then
                                        acadButtonObject.Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(itemSmallImage.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(itemSmallImage.Width, itemSmallImage.Height))
                                    End If
                                    If itemLargeImage IsNot Nothing Then
                                        acadButtonObject.LargeImage = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(itemLargeImage.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(itemLargeImage.Width, itemLargeImage.Height))
                                    End If
                                    If itemShowText AndAlso Not String.IsNullOrEmpty(itemText) Then
                                        acadButtonObject.Text = itemText
                                    End If
                                    If Not String.IsNullOrEmpty(itemDescription) Then
                                        Dim buttonToolTip As New RibbonToolTip()
                                        buttonToolTip.Title = itemName
                                        buttonToolTip.Content = itemDescription
                                        If itemLargeImage IsNot Nothing Then
                                            buttonToolTip.Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(itemLargeImage.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(itemLargeImage.Width, itemLargeImage.Height))
                                        End If
                                        acadButtonObject.ToolTip = buttonToolTip
                                        acadButtonObject.Description = itemDescription
                                    End If
                                    acadButtonObject.CommandHandler = New ACADRibbonCommandHandler(manager)
                                    acadRowObject.Items.Add(acadButtonObject)
                                    Dim button As New ACADRibbonButton(itemID, itemGUID, itemName, itemTypeID, itemPositoin, itemText, itemDescription, itemShowText, itemShowImage, itemSmallImage, itemLargeImage, itemVisible, itemEnabled, row, acadButtonObject, itemActions)
                                    row.Items.Add(button)
                                Case 2
                                    'Ribbon Menu
                                    'Proceed if Ribbon Item has Values
                                    If RibbonData.Tables("AutoCAD_Ribbon_Item_Value").Select("AutoCAD_Ribbon_Item_ID = " + itemRow("ID").ToString()).Count() > 0 Then
                                        Dim acadMenuObject As New RibbonMenuButton()
                                        acadMenuObject.Name = itemName
                                        acadMenuObject.Id = itemGUID
                                        acadMenuObject.Tag = itemID
                                        acadMenuObject.ShowImage = itemShowImage
                                        acadMenuObject.ShowText = itemShowText
                                        If itemSmallImage IsNot Nothing Then
                                            acadMenuObject.Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(itemSmallImage.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(itemSmallImage.Width, itemSmallImage.Height))
                                        End If
                                        If itemLargeImage IsNot Nothing Then
                                            acadMenuObject.LargeImage = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(itemLargeImage.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(itemLargeImage.Width, itemLargeImage.Height))
                                        End If
                                        If itemShowText AndAlso Not String.IsNullOrEmpty(itemText) Then
                                            acadMenuObject.Text = itemText
                                        End If
                                        If Not String.IsNullOrEmpty(itemDescription) Then
                                            Dim buttonToolTip As New RibbonToolTip()
                                            buttonToolTip.Title = itemName
                                            buttonToolTip.Content = itemDescription
                                            If itemLargeImage IsNot Nothing Then
                                                buttonToolTip.Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(itemLargeImage.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(itemLargeImage.Width, itemLargeImage.Height))
                                            End If
                                            acadMenuObject.ToolTip = buttonToolTip
                                            acadMenuObject.Description = itemDescription
                                        End If
                                        Dim menu As New ACADRibbonMenu(itemID, itemGUID, itemName, itemTypeID, itemPositoin, itemText, itemDescription, itemShowText, itemShowImage, itemSmallImage, itemLargeImage, itemVisible, itemEnabled, Nothing, row, acadMenuObject, New List(Of ACADRibbonItemAction))
                                        For Each itemValueRow As DataRow In RibbonData.Tables("AutoCAD_Ribbon_Item_Value").Select("AutoCAD_Ribbon_Item_ID = " + itemRow("ID").ToString(), "Position")
                                            Dim itemValueID As Integer = Convert.ToInt32(itemValueRow("ID"))
                                            Dim itemValueGUID As String = Guid.NewGuid.ToString()
                                            Dim itemValueName As String = itemValueRow("Name").ToString()
                                            Dim itemValuePosition As Integer = Convert.ToInt32(itemValueRow("Position"))
                                            Dim itemValueText As String = itemValueRow("Item_Value").ToString()
                                            Dim itemValueDescription = IIf(itemValueRow.IsNull("Tool_Tip"), Nothing, itemValueRow("Tool_Tip").ToString())
                                            Dim itemValueDefaultSelection As Boolean = itemValueRow("Default_Selection")
                                            Dim itemValueImage As Bitmap = Nothing
                                            If Not itemValueRow.IsNull("Value_Image") Then
                                                Using ms As New MemoryStream(DirectCast(itemValueRow("Value_Image"), Byte()))
                                                    Dim bmp As New Bitmap(ms)
                                                    itemValueImage = bmp
                                                End Using
                                            End If
                                            Dim acadMenuItemObject As New RibbonMenuItem()
                                            With acadMenuItemObject
                                                .Id = itemValueGUID
                                                .Tag = itemValueID
                                                .Name = itemValueName
                                                .Text = itemValueText
                                                If itemValueImage IsNot Nothing Then
                                                    .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(itemValueImage.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(itemValueImage.Width, itemValueImage.Height))
                                                End If
                                                If Not String.IsNullOrEmpty(itemValueDescription) Then
                                                    .Description = itemValueDescription
                                                    Dim itemToolTip As New RibbonToolTip()
                                                    itemToolTip.Title = itemValueText
                                                    itemToolTip.Content = itemValueDescription
                                                    .ToolTip = itemToolTip
                                                End If
                                                .CommandHandler = New ACADRibbonCommandHandler(manager)
                                            End With
                                            Dim itemValueActions As New List(Of ACADRibbonItemAction)
                                            For Each actionRow As DataRow In (From n In RibbonData.Tables("AutoCAD_Ribbon_Item_Value_Action") Where n("AutoCAD_Ribbon_Item_Value_ID") = itemValueID Select n Order By Convert.ToInt32(n("Position")))
                                                Dim actionTypeID As Integer = actionRow("AutoCAD_Ribbon_Item_Action_Type_ID")
                                                Select Case actionTypeID
                                                    Case WF_RIBBON_ACTION_TYPE_ID
                                                        itemValueActions.Add(New ACADRibbonItemAction(RibbonObjectType.ItemValue, RibbonItemActionType.RunWorkflow, Convert.ToInt32(actionRow("Position")), actionRow("Action_Data").ToString()))
                                                    Case ACCESSORY_RIBBON_ACTION_TYPE_ID
                                                        itemValueActions.Add(New ACADRibbonItemAction(RibbonObjectType.ItemValue, RibbonItemActionType.AddAccessory, Convert.ToInt32(actionRow("Position")), actionRow("Action_Data").ToString()))
                                                    Case SHOW_FACTORY_CATEGORY_RIBBON_ACTION_TYPE_ID
                                                        itemValueActions.Add(New ACADRibbonItemAction(RibbonObjectType.ItemValue, RibbonItemActionType.ShowFactoryCategory, Convert.ToInt32(actionRow("Position")), actionRow("Action_Data").ToString()))
                                                    Case Else
                                                        Throw New NotSupportedException("AutoCAD_Ribbon_Item_Action_Type_ID invalid where AutoCAD_Ribbon_Item_Value_Action_ID = " + actionRow("ID").ToString())
                                                End Select
                                            Next
                                            Dim menuItem As New ACADRibbonMenuItem(itemValueID, itemValueGUID, itemValueName, itemValuePosition, itemValueText, itemValueDescription, itemValueImage, itemValueDefaultSelection, menu, acadMenuItemObject, itemValueActions)
                                            acadMenuObject.Items.Add(acadMenuItemObject)
                                            menu.MenuItems.Add(menuItem)
                                        Next
                                        acadRowObject.Items.Add(acadMenuObject)
                                    End If
                            End Select
                        Next
                        panel.Rows.Add(row)
                        acadPanelSourceObject.Items.Add(acadRowObject)
                        acadPanelSourceObject.Items.Add(New RibbonRowBreak())
                    Next
                End If
                acadTabObject.Panels.Add(acadPanelObject)
                tab.Panels.Add(panel)
            Next
            ribbonTabs.Add(tab)
            Autodesk.Windows.ComponentManager.Ribbon.Tabs.Add(acadTabObject)
        Next
        Return manager
    End Function

    Private Shared Sub BuildNiCRibbonPanelRow1(Manager As ACADRibbonManager, ACADRowObject As RibbonRowPanel)
        'Active Conveyor Menu
        Dim activeConveyorLabel As New RibbonLabel()
        activeConveyorLabel.Text = "Conv. #"
        ACADRowObject.Items.Add(activeConveyorLabel)
        Dim activeConveyorRibbonCombo As New RibbonCombo()
        Manager.ActiveConveyorRibbonCombo = activeConveyorRibbonCombo
        activeConveyorRibbonCombo.Name = "Active Conveyor"
        activeConveyorRibbonCombo.Id = ACAD_RIBBON_ACTIVECONVEYOR_ITEM_ID
        activeConveyorRibbonCombo.Tag = ACAD_RIBBON_ACTIVECONVEYOR_ITEM_ID
        activeConveyorRibbonCombo.ShowImage = False
        activeConveyorRibbonCombo.IsEditable = False
        activeConveyorRibbonCombo.Width = 75
        If AutoPriceApp.Drawings.ActiveDrawing IsNot Nothing AndAlso AutoPriceApp.Drawings.ActiveDrawing.ActiveEstimate IsNot Nothing Then
            For Each conveyor As ConveyorModel In AutoPriceApp.Drawings.ActiveDrawing.ActiveEstimate.Conveyors
                Dim conveyorButton As New RibbonButton()
                conveyorButton.Id = conveyor.ID
                conveyorButton.Tag = conveyor.ID
                conveyorButton.ShowText = True
                conveyorButton.ShowImage = False
                conveyorButton.Text = conveyor.Name
                activeConveyorRibbonCombo.Items.Add(conveyorButton)
                If AutoPriceApp.Drawings.ActiveDrawing.ActiveEstimate.ActiveConveyor IsNot Nothing AndAlso conveyor.ID = AutoPriceApp.Drawings.ActiveDrawing.ActiveEstimate.ActiveConveyor.ID Then
                    activeConveyorRibbonCombo.Current = conveyorButton
                End If
            Next
        End If
        AddHandler activeConveyorRibbonCombo.CurrentChanged, AddressOf Manager.OnActiveConveyorRibbonCombo_Changed
        ACADRowObject.Items.Add(activeConveyorRibbonCombo)
        'New Conveyor Button
        Dim newConveyorRibbonButton As New RibbonButton()
        newConveyorRibbonButton.Name = "NiCNewConveyorButton"
        newConveyorRibbonButton.Id = ACAD_RIBBON_NEWCONVEYOR_ITEM_ID
        newConveyorRibbonButton.Tag = ACAD_RIBBON_NEWCONVEYOR_ITEM_ID
        newConveyorRibbonButton.ShowImage = True
        newConveyorRibbonButton.ShowText = False
        newConveyorRibbonButton.Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.AddConveyor.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.AddConveyor.Width, My.Resources.AddConveyor.Height))
        Dim newConveyorToolTip As New RibbonToolTip()
        newConveyorToolTip.Title = "New Conveyor"
        newConveyorToolTip.Content = "Add a new Conveyor to the Active Estimate either manually or via a Conveyor Factory."
        newConveyorRibbonButton.ToolTip = newConveyorToolTip
        newConveyorRibbonButton.CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        ACADRowObject.Items.Add(newConveyorRibbonButton)
        'Conveyor Prompt Editor Button
        Dim promptEditorRibbonButton As New RibbonButton()
        With promptEditorRibbonButton
            .Name = "NiCConveyorPromptEditorButton"
            .Id = ACAD_RIBBON_CONVEYORPROMPTEDITOR_ITEM_ID
            .Tag = ACAD_RIBBON_CONVEYORPROMPTEDITOR_ITEM_ID
            .ShowImage = True
            .ShowText = False
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.EditConveyorPrompts.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.EditConveyorPrompts.Width, My.Resources.EditConveyorPrompts.Height))
        End With
        Dim promptEditorTooTip As New RibbonToolTip()
        With promptEditorTooTip
            .Title = "Conveyor Prompt Editor"
            .Content = "Edit the Prompts of the Active Conveyor, such as Live Load and Nominal Width."
        End With
        promptEditorRibbonButton.ToolTip = promptEditorTooTip
        promptEditorRibbonButton.CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        ACADRowObject.Items.Add(promptEditorRibbonButton)
        'User-Defined Defaults Editor Button
        Dim defaultsEditorRibbonButton As New RibbonButton()
        With defaultsEditorRibbonButton
            .Name = "NiCUserDefinedDefaultsEditorButton"
            .Id = ACAD_RIBBON_DEFAULTSEDITOR_ITEM_ID
            .Tag = ACAD_RIBBON_DEFAULTSEDITOR_ITEM_ID
            .ShowImage = True
            .ShowText = False
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.EditUserDefinedDefaults.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.EditUserDefinedDefaults.Width, My.Resources.EditUserDefinedDefaults.Height))
            Dim defaultsPromptToolTip As New RibbonToolTip()
            defaultsPromptToolTip.Title = "User-Defined Defaults Editor"
            defaultsPromptToolTip.Content = "Edit User-Defined Defaults by Conveyor Type."
            .ToolTip = defaultsPromptToolTip
            .CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        End With
        ACADRowObject.Items.Add(defaultsEditorRibbonButton)
    End Sub

    Private Shared Sub BuildNiCRibbonPanelRow2(Manager As ACADRibbonManager, ACADRowObject As RibbonRowPanel)
        'Accessory Editor Button
        Dim accessoryEditorRibbonButton As New RibbonButton()
        With accessoryEditorRibbonButton
            .Name = "NiCAccessoryEditorButton"
            .Id = ACAD_RIBBON_ACCESSORIESEDITOR_ITEM_ID
            .Tag = ACAD_RIBBON_ACCESSORIESEDITOR_ITEM_ID
            .ShowImage = True
            .ShowText = False
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.AccessoryEditor.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.AccessoryEditor.Width, My.Resources.AccessoryEditor.Height))
            Dim accessoryPromptToolTip As New RibbonToolTip()
            accessoryPromptToolTip.Title = "Accessory Editor"
            accessoryPromptToolTip.Content = "Edit Accessories of Active Conveyor."
            .ToolTip = accessoryPromptToolTip
            .CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        End With
        ACADRowObject.Items.Add(accessoryEditorRibbonButton)
        'Guardrail Editor Button
        Dim guardrailEditorRibbonButton As New RibbonButton()
        With guardrailEditorRibbonButton
            .Name = "NiCGuardrailEditorButton"
            .Id = ACAD_RIBBON_GREDITOR_ITEM_ID
            .Tag = ACAD_RIBBON_GREDITOR_ITEM_ID
            .ShowImage = True
            .ShowText = False
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.GuardrailEditor.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.GuardrailEditor.Width, My.Resources.GuardrailEditor.Height))
            Dim guardrailPromptToolTip As New RibbonToolTip()
            guardrailPromptToolTip.Title = "Guardrail Editor"
            guardrailPromptToolTip.Content = "Edit Guardrail of Active Conveyor."
            .ToolTip = guardrailPromptToolTip
            .CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        End With
        ACADRowObject.Items.Add(guardrailEditorRibbonButton)
        'Parts Editor Button
        Dim partsEditorRibbonButton As New RibbonButton()
        With partsEditorRibbonButton
            .Name = "NiCGuardrailEditorButton"
            .Id = ACAD_RIBBON_PARTSEDITOR_ITEM_ID
            .Tag = ACAD_RIBBON_PARTSEDITOR_ITEM_ID
            .ShowImage = True
            .ShowText = False
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.PartEditor.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.PartEditor.Width, My.Resources.PartEditor.Height))
            Dim partsPromptToolTip As New RibbonToolTip()
            partsPromptToolTip.Title = "Misc. Part Editor"
            partsPromptToolTip.Content = "Edit Misc. Parts of Active Conveyor."
            .ToolTip = partsPromptToolTip
            .CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        End With
        ACADRowObject.Items.Add(partsEditorRibbonButton)
        'Specials Editor Button
        Dim specialsEditorRibbonButton As New RibbonButton()
        With specialsEditorRibbonButton
            .Name = "NiCSpecialsEditorButton"
            .Id = ACAD_RIBBON_SPECIALSEDITOR_ITEM_ID
            .Tag = ACAD_RIBBON_SPECIALSEDITOR_ITEM_ID
            .ShowImage = True
            .ShowText = False
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.SpecialItemEditor.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.SpecialItemEditor.Width, My.Resources.SpecialItemEditor.Height))
            Dim specialsPromptToolTip As New RibbonToolTip()
            specialsPromptToolTip.Title = "Special Item Editor"
            specialsPromptToolTip.Content = "Edit Special Items of Active Conveyor."
            .ToolTip = specialsPromptToolTip
            .CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        End With
        ACADRowObject.Items.Add(specialsEditorRibbonButton)
        Dim reportViewerRibbonButton As New RibbonButton()
        With reportViewerRibbonButton
            .Name = "NiCReportViewerButton"
            .Id = ACAD_RIBBON_REPORTVIEWER_ITEM_ID
            .Tag = ACAD_RIBBON_REPORTVIEWER_ITEM_ID
            .ShowImage = True
            .ShowText = False
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.book_reportHS.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.book_reportHS.Width, My.Resources.book_reportHS.Height))
            Dim reportViewerPromptToolTip As New RibbonToolTip()
            reportViewerPromptToolTip.Title = "Report Viewer"
            reportViewerPromptToolTip.Content = "Open Report Viewer."
            .ToolTip = reportViewerPromptToolTip
            .CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        End With
        ACADRowObject.Items.Add(reportViewerRibbonButton)
    End Sub

    Private Shared Sub BuildNiCRibbonPanelRow3(Manager As ACADRibbonManager, ACADRowObject As RibbonRowPanel)
        'Select All Button
        Dim selectAllRibbonButton As New RibbonButton()
        With selectAllRibbonButton
            .Name = "NiCSelectAllButton"
            .Id = ACAD_RIBBON_SELECTALL_ITEM_ID
            .Tag = ACAD_RIBBON_SELECTALL_ITEM_ID
            .ShowText = False
            .ShowImage = True
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.quick_select_16x16.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.quick_select_16x16.Width, My.Resources.quick_select_16x16.Height))
            Dim selectAllToolTip As New RibbonToolTip()
            selectAllToolTip.Title = "Select All Conveyor Blocks"
            selectAllToolTip.Content = "Select all Blocks belonging to selected Conveyor(s)."
            .ToolTip = selectAllToolTip
            .CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        End With
        ACADRowObject.Items.Add(selectAllRibbonButton)
        'Zoom Button
        Dim zoomRibbonButton As New RibbonButton()
        With zoomRibbonButton
            .Name = "NiCZoomButton"
            .Id = ACAD_RIBBON_ZOOM_ITEM_ID
            .Tag = ACAD_RIBBON_ZOOM_ITEM_ID
            .ShowText = False
            .ShowImage = True
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.zoom_16x16.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.zoom_16x16.Width, My.Resources.zoom_16x16.Height))
            Dim zoomToolTip As New RibbonToolTip()
            zoomToolTip.Title = "Zoom To Conveyor Extents"
            zoomToolTip.Content = "Zoom to Active Conveyor extents."
            .ToolTip = zoomToolTip
            .CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        End With
        ACADRowObject.Items.Add(zoomRibbonButton)
        'Isolate Toggle Button
        Dim isolateRibbonToggleButton As New RibbonToggleButton()
        Manager.IsolateRibbonToggleButton = isolateRibbonToggleButton
        With isolateRibbonToggleButton
            .Name = "NiCIsolateButton"
            .Id = ACAD_RIBBON_ISOLATE_ITEM_ID
            .Tag = ACAD_RIBBON_ISOLATE_ITEM_ID
            .ShowText = False
            .ShowImage = True
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.isolateobjects_16x16.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.isolateobjects_16x16.Width, My.Resources.isolateobjects_16x16.Height))
            Dim isolateToolTip As New RibbonToolTip()
            isolateToolTip.Title = "Isolate Selected Conveyor(s)"
            isolateToolTip.Content = "Isolate Blocks of Selected Covneyor(s)."
            .ToolTip = isolateToolTip
            .CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        End With
        ACADRowObject.Items.Add(isolateRibbonToggleButton)
        'Hide Toggle Button
        Dim hideRibbonToggleButton As New RibbonToggleButton()
        Manager.HideRibbonToggleButton = hideRibbonToggleButton
        With hideRibbonToggleButton
            .Name = "NiCHideButton"
            .Id = ACAD_RIBBON_HIDE_ITEM_ID
            .Tag = ACAD_RIBBON_HIDE_ITEM_ID
            .ShowText = False
            .ShowImage = True
            .Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(My.Resources.hideobjects_16x16.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(My.Resources.hideobjects_16x16.Width, My.Resources.hideobjects_16x16.Height))
            Dim hideToolTip As New RibbonToolTip()
            hideToolTip.Title = "Hide Selected Conveyor(s)"
            hideToolTip.Content = "Hide Blocks of Selected Covneyor(s)."
            .ToolTip = hideToolTip
            .CommandHandler = New ACADRibbonStaticItemCommandHandler(Manager)
        End With
        ACADRowObject.Items.Add(hideRibbonToggleButton)
    End Sub

End Class

 

The BuildACADRibbon method is initially invoked. Note that one or more ribbon tabs could be created by this code, depending on the data provided. However, only one ribbon is created currently. If this code has run and my application's ribbon tab is created, the exception occurs when searching. If not, there is no exception. Really I'm just looking for advice about how this exception can be avoided and where I should look for the most likely source of the exception.

 

Also note that this is a very large plugin (likely hundreds of thousands of lines of code), so providing the full source is just not practical.

 

Thank you in advance.

 

Best Regards,

Kevin Brown

 

2 REPLIES 2
Message 2 of 3
Balaji_Ram
in reply to: kbrown

Hi Kevin,

 

Sorry, we will need to reproduce the crash to know what is causing it.

 

I started with a simple VB.Net project that creates a ribbon tab at runtime and used the search option in AutoCAD 2014.

 

I still haven't reproduced the crash. 

 

Can you try the attached project and include any specific details that your actual project might be doing to it ?

 

This will help us investigate this further.

 

Thank you.

 

Balaji

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Message 3 of 3
kbrown
in reply to: Balaji_Ram

Balaji,

 

Sorry I haven't responded; I was off work for several days. Providing you with a runnable project which reproduces the issue will take time I don't have right now. I will try to get back to you with what you have asked for later this week or next week.

 

Thank you,

Kevin Brown

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost