This example expects to find 3 external rules called:
- Spoon Rule
- Fork Rule
- Knife Rule
you would change the names in the sub routines to match the name of your rules, and add subs as needed to add more buttons to the ribbon.
This example creates a "My _____ Tools' Panel on the tools tab of the ribbon for the file type of the active file.
Start the VBA editor

- Locate the Modules folder in the Application Project and right click on it and choose Insert > Module
- Rename the Module something like Module_CustomRibbon
- Paste in this code:
Sub Customize_Ribbon()
ThisApplication.SilentOperation = True
'silently create file of type
'set the custom ribbon panel
'then close the file
' Create a new Assembly document, using the default Assembly template.
Dim oAssemblyDoc As AssemblyDocument
Set oAssemblyDoc = ThisApplication.Documents.Add(kAssemblyDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kAssemblyDocumentObject), True)
Call SetRibbon
oAssemblyDoc.Close
' Create a new Drawing document, using the default Drawing template.
Dim oDrawDoc As DrawingDocument
sTemplate = "\\SERVER\Departments\CAD\Inventor\Macros\Macro_Template.idw"
Set oDrawDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, _
sTemplate, True)
Call SetRibbon
oDrawDoc.Close
' Create a new part document, using the default part template.
Dim oPartDoc As PartDocument
Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject), True)
Call SetRibbon
oPartDoc.Close
ThisApplication.SilentOperation = False
End Sub
Sub SetRibbon()
Dim oRibbon As Inventor.Ribbon
'determine file type
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Set oRibbon = ThisApplication.UserInterfaceManager.Ribbons.Item("Assembly")
oType = "Assembly"
ElseIf ThisApplication.ActiveDocumentType = DocumentTypeEnum.kPartDocumentObject Then
Set oRibbon = ThisApplication.UserInterfaceManager.Ribbons.Item("Part")
oType = "Part"
ElseIf ThisApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
Set oRibbon = ThisApplication.UserInterfaceManager.Ribbons.Item("Drawing")
oType = "Drawing"
Else
oType = "Unknown"
End If
If oType = "Unknown" Then
Exit Sub
End If
'Get the "Tools" tabs
Dim oTab As RibbonTab
Set oTab = oRibbon.RibbonTabs.Item("id_TabTools")
oTab.Active = True
'clean up existing custom panels
'this prevents errors when panels
'already exists
Dim oPanel As RibbonPanel
For Each oPanel In oTab.RibbonPanels
If oPanel.DisplayName = "My Assembly Tools" _
Or oPanel.DisplayName = "My Drawing Tools" _
Or oPanel.DisplayName = "My Part Tools" Then
oPanel.Delete 'remove it
End If
Next
' Create a panels
Dim oPanel_Assem As RibbonPanel
Set oPanel_Assem = oTab.RibbonPanels.Add("My Assembly Tools", "ToolsTabAssemPanel", "SampleClientId")
Dim oPanel_Draw As RibbonPanel
Set oPanel_Draw = oTab.RibbonPanels.Add("My Drawing Tools", "ToolsTabDrawPanel", "SampleClientId")
Dim oPanel_Part As RibbonPanel
Set oPanel_Part = oTab.RibbonPanels.Add("My Part Tools", "ToolsTabPartPanel", "SampleClientId-3")
Dim oMacroDef As MacroControlDefinition
If oType = "Assembly" Then
Set oMacroDef = ThisApplication.CommandManager.ControlDefinitions. _
AddMacroControlDefinition("Module_iLogicRules.Bend Spoon Rule")
oPanel_Assem.CommandControls.AddMacro oMacroDef, False
Set oMacroDef = ThisApplication.CommandManager.ControlDefinitions. _
AddMacroControlDefinition("Module_iLogicRules.Bend Fork Rule")
oPanel_Assem.CommandControls.AddMacro oMacroDef, False
Set oMacroDef = ThisApplication.CommandManager.ControlDefinitions. _
AddMacroControlDefinition("Module_iLogicRules.Bend Knife Rule")
oPanel_Assem.CommandControls.AddMacro oMacroDef, False
ElseIf oType = "Drawing" Then
'add drawing rules code here
ElseIf oType = "Part" Then
'add part rules code here
End If
End Sub
- Again locate the Modules folder in the Application Project and right click on it and choose Insert > Module
- Rename the Module something like "Module_iLogicRules"
- Paste in this code:
'Module_iLogicRules
'this module allows iLogic rules to be triggered
'from a VBA macro, fired from a ribbon button
Public Sub Spoon_rule()
'ilogic rule name:
RuniLogicExt "Bend Spoon Rule"
End Sub
Public Sub Fork_Rule()
'ilogic rule name:
RuniLogicExt "Bend Fork Rule"
End Sub
Public Sub Knife_Rule()
'ilogic rule name:
RuniLogicExt "Bend Knife Rule"
End Sub
Public Sub RuniLogicExt(ByVal RuleName As String)
Dim oPath As String
oPath = "\\server\departments\CAD\Inventor\iLogic\"
Dim iLogicAuto As Object
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
If oDoc Is Nothing Then
MsgBox "Missing Inventor Document"
Exit Sub
End If
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then
MsgBox "iLogicAuto Is Nothing"
Exit Sub
End If
iLogicAuto.RunExternalRule oDoc, oPath & RuleName & ".iLogicVb"
End Sub
Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Set addIns = oApplication.ApplicationAddIns
Dim addIn As ApplicationAddIn
On Error GoTo NotFound
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
If (addIn Is Nothing) Then Exit Function
addIn.Activate
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:
End Function
Example result for an assembly file
