ilogic - adding macro buttons to a custom ribbon tab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a question for anyone who might have a minute to look at this issue. I can't tell if there is a bug here or I'm just doing something wrong.
I have this simple test rule that either adds built in command buttons to a custom ribbon tab, or it adds macro buttons to this same tab, but it has a problem when adding the macro buttons.
this rule looks at the active document type to get the ribbon for the document type, then it deletes an existing tab if present, then it (re)creates that tab, creates a panel on that tap, and then creates buttons on that panel based on a predefined list.
These are the built in commands that it add to the new ribbon tab
The problem is that for macro buttons it only adds the last button in the list to the panel, whereas for the built in commands it adds them all/both
To test this using the code below you can:
- create a VBA module called "Test" as shown:
2. Then paste in this code to the new module:
Sub Test_01() MsgBox ("Test 01") End Sub Sub Test_02() MsgBox ("Test 02") End Sub Sub Test_03() MsgBox ("Test 03") End Sub Sub Test_04() MsgBox ("Test 04") End Sub Sub Test_05() MsgBox ("Test 05") End Sub Sub Test_06() MsgBox ("Test 06") End Sub
3. Then create an external ilogic rule and paste this in:
oCommandType = InputRadioBox("Select One", _ "Built in commands", "Macro commands", False, "ilogic") ' Get the ribbon associated with the document Dim oRibbon As Inventor.Ribbon Dim oDoc As Document oDoc = ThisApplication.ActiveEditDocument If oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then oRibbon = ThisApplication.UserInterfaceManager.Ribbons.Item("Assembly") oType = "Assembly" ElseIf oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then oRibbon = ThisApplication.UserInterfaceManager.Ribbons.Item("Part") oType = "Part" ElseIf oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then oRibbon = ThisApplication.UserInterfaceManager.Ribbons.Item("Drawing") oType = "Drawing" Else oType = "Unknown" Exit Sub End If oName = "TEST_" 'delete existing tab, in case it exist from previous test Try oRibbon.RibbonTabs.Item(oName & oType).Delete Catch End Try Dim oTab As Inventor.RibbonTab oTab = oRibbon.RibbonTabs.Add(oName & oType, oName & oType, "ClientId123") oTab.Active = True Dim oPanel As RibbonPanel sPanelName = oName & " Tools" oPanel = oTab.RibbonPanels.Add(sPanelName, sPanelName & "_" & oType, sPanelName & "_" & oType) Dim oControlDefs As ControlDefinitions oControlDefs = ThisApplication.CommandManager.ControlDefinitions Dim oButtonsList As New ArrayList If oCommandType = False If oType = "Drawing" Then oButtonsList.Add("Test.Test_01") oButtonsList.Add("Test.Test_02") Else If oType = "Assembly" Then oButtonsList.Add("Test.Test_03") oButtonsList.Add("Test.Test_04") Else If oType = "Part" Then oButtonsList.Add("Test.Test_05") oButtonsList.Add("Test.Test_06") End If Dim oMacroDef As MacroControlDefinition For Each oItem In oButtonsList oMacroDef = oControlDefs.AddMacroControlDefinition(oItem) oPanel.CommandControls.AddMacro(oMacroDef, False) Next Else If oType = "Drawing" Then oButtonsList.Add("DrawingBalloonCmd") oButtonsList.Add("DrawingBalloonAllCmd") Else If oType = "Assembly" Then oButtonsList.Add("AppZoomSelectCmd") oButtonsList.Add("AppZoomAllCmd") Else If oType = "Part" Then oButtonsList.Add("PartExtrudeCmd") oButtonsList.Add("PartRevolveCmd") End If Dim oButtonDef As ButtonDefinition For Each oItem In oButtonsList oButtonDef = oControlDefs.Item(oItem) oPanel.CommandControls.AddButton(oButtonDef, False) Next End If
4. then open a part file and run this rule to create macro buttons
5. then do the same for an assembly
6. then do the same for a drawing
7. note that the issue seems to occur, on the third document type this is used in, and then persists for any and all documents after that