Execute Global Rule from VBA Editor

Execute Global Rule from VBA Editor

bsnyderACLUW
Enthusiast Enthusiast
1,005 Views
5 Replies
Message 1 of 6

Execute Global Rule from VBA Editor

bsnyderACLUW
Enthusiast
Enthusiast

Currently my organization has an iLogic rule set we use to streamline our work productivity.

What I am trying to do is move this from an independent Global Forms window to the Inventor ribbon. I have created a bit of iLogic code to create a new ribbon tab (with the help of some research done on this forum). I can get this code  to reference a module in VBA Editor but i can't figure out how to get VBA to run an iLogic rule. 

 

For instance, one of the rules used by our company is "Add_Revision_Row". I have made a button that appears on the ribbon labled Add_Revision_Row that I can click on to create a message box by using a bit of code in VBA:

 

Public Sub Add_Revision_Row()

    MsgBox ("test 1")

End Sub

 

So I know everything works on the iLogic side of the code, but I am at a loss as to what needs to be in this module within VBA to get it to run a Global Form. 

 

Any help would be appreciated.

 

Thanks,

0 Likes
Accepted solutions (1)
1,006 Views
5 Replies
Replies (5)
Message 2 of 6

JelteDeJong
Mentor
Mentor

i think this post answers your question:

https://forums.autodesk.com/t5/inventor-customization/launch-external-ilogic-rule-with-vba/m-p/31708... 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 6

bsnyderACLUW
Enthusiast
Enthusiast

I have seen that posting before, and just  it but there is a problem I don't know the answer too. 

it seems to error out on

 

Function GetiLogicAddin(oApplication As Inventor.Application) As Object

(error msgbox attached to posting)

 

I don't know what the problem is or how to fix it.

 

any help would be great.

 

thanks,

0 Likes
Message 4 of 6

JelteDeJong
Mentor
Mentor
Accepted solution

I didnt see it before but the first solution in the post is not complete. did also try the 2e soulution.

https://forums.autodesk.com/t5/inventor-customization/launch-external-ilogic-rule-with-vba/m-p/31779... 

It works for me.

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 5 of 6

bsnyderACLUW
Enthusiast
Enthusiast

ok, so its been a while since I have worked on this issue. I have the program fixed now, was an issue with this call out:

iLogicAuto.RunRule oDoc, Add_Revision_Row

changed to

iLogicAuto.RunExternalRule oDoc, Add_Revision_Row

 

 I do want to take this a step further and divide some of the functions up into there own panels. I have tried to look this up and have had no luck. all I find is how to customize standard tabs using the editor. I want to include something into the code that will not only create the tab but also panels where I can divide the functions with.

 

thanks,

0 Likes
Message 6 of 6

bsnyderACLUW
Enthusiast
Enthusiast

ok so here is an update

 

I have figured out how to divide some of these functions into separate

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       '<-------- if, else if refrences opened file for name nomenclature 

oName = "Silent-Aire_"   '<---- name nomenclature

Try
oRibbon.RibbonTabs.Item(oName & oType).Delete     '<------finds if old tab is present and deletes it
Catch
End Try

Dim oControlDefs As ControlDefinitions
oControlDefs = ThisApplication.CommandManager.ControlDefinitions                '<----- tells inventor that comands will be executed on this file

Dim oTab As Inventor.RibbonTab
oTab = oRibbon.RibbonTabs.Add(oName & oType, oName & oType, “Silent-Aire”)      '<----- creates ribbon tab
oTab.Active = True
	
	
	
	
	
	
	
Dim oPanel As RibbonPanel
sPanelName = "Tools"
oPanel = oTab.RibbonPanels.Add(sPanelName, oName & oType, oName & oType)                 '<----- creates first panel on ribbon tab
Dim aButtonsList As New ArrayList
If oType = "Drawing" Then	'<----- this section creates the clickable buttons
	aButtonsList.Add("Ribbon_Executables.Reuse_Drawing")                                 '<-----(VBA code name.button name)
	aButtonsList.Add("Ribbon_Executables.Center_Dimensions")
	aButtonsList.Add("Ribbon_Executables.Missing_Balloons")
	aButtonsList.Add("Ribbon_Executables.Sort_and_Hide_Partlist")	
Else If oType = "Assembly" Then
	aButtonsList.Add("Ribbon_Executables.Open_All_Drawings")
	aButtonsList.Add("Ribbon_Executables.Go_To_Working_Folder")	
	aButtonsList.Add("Ribbon_Executables.Total_Weight")
	aButtonsList.Add("Ribbon_Executables.Creat_Part_Drawing")
	aButtonsList.Add("Ribbon_Executables.Excel_BOM_Export")	
Else If oType = "Part" Then
	aButtonsList.Add("Ribbon_Executables.Open_All_Drawings")
	aButtonsList.Add("Ribbon_Executables.Go_To_Working_Folder")	
	aButtonsList.Add("Ribbon_Executables.Density")
	aButtonsList.Add("Ribbon_Executables.Creat_Part_Drawing")
	aButtonsList.Add("Ribbon_Executables.Copy_Design")
	aButtonsList.Add("Ribbon_Executables.Copy_Design")
End If
	
Dim aMacroDef As MacroControlDefinition                                        
For Each oItem In aButtonsList
aMacroDef = oControlDefs.AddMacroControlDefinition(oItem)	                               '<----- tells inventor that these buttons will execute a command in VBA
	oPanel.CommandControls.AddMacro(aMacroDef, False)	
Next






Dim oRevisionPanel As RibbonPanel
sRevisionPanelName = "Revision Block"
oRevisionPanel= oTab.RibbonPanels.Add(sRevisionPanelName, orevName & oType, orevName & oType)    '<----- creates second panel on ribbon tab
Dim bButtonsList As New ArrayList
If oType = "Drawing" Then	                                                               '<----- this section creates the clickable buttons
	bButtonsList.Add("Ribbon_Executables.Issued_For_Construction")
	bButtonsList.Add("Ribbon_Executables.Add_Revision_Row")
	bButtonsList.Add("Ribbon_Executables.Hide_Revision_Row")
	bButtonsList.Add("Ribbon_Executables.Clear_Revisions_Batch")
	bButtonsList.Add("Ribbon_Executables.Clear_Revisions_Single")
End If
	
Dim bMacroDef As MacroControlDefinition      
For Each oItem In bButtonsList
bMacroDef = oControlDefs.AddMacroControlDefinition(oItem)	                              '<----- tells inventor that these buttons will execute a command in VBA
	oRevisionPanel.CommandControls.AddMacro(bMacroDef, False)	
Next







'Dim oPDFPanel As RibbonPanel
'sPDFPanelName = "PDF Block"
'oPDFPanel= oTab.RibbonPanels.Add(sPDFPanelName, oPDFName & oType, oPDFName & oType)              '<----- creates second panel on ribbon tab
'Dim cButtonsList As New ArrayList
'If oType = "Drawing" Then	                                                               '<----- this section creates the clickable buttons
'	cButtonsList.Add("Ribbon_Executables.Batch_Print_to_PDF")
'	cButtonsList.Add("Ribbon_Executables.Single_Print_to_PDF")
'End If
	
'Dim cMacroDef As MacroControlDefinition      
'For Each oItem In cButtonsList
'cMacroDef = oControlDefs.AddMacroControlDefinition(oItem)	                                '<----- tells inventor that these buttons will execute a command in VBA
'	oPDFPanel.CommandControls.AddMacro(cMacroDef, False)	
'Next

panels on the same tab but for some reason I can only create 2 panels. the moment I add the third panel the code errors out. does anyone know anything about this?

0 Likes