@LukeDavenport wrote:
https://inventorlogicblog.wordpress.com/2016/04/20/autodesk-inventor-ilogic-create-a-new-ilogic-rule...
I adapted the above mentioned code for use in the VBA editor.
@Anonymous wrote:
Object reference not set to an instance of an object.
This problem is fixed as well.
Sub AddInternalDummyRuleTest()
Call AddInternalDummyRule(ThisApplication.ActiveDocument)
End Sub
Function AddInternalDummyRule(Doc As Document, Optional OverWrite As Boolean = False)
'adapted from: https://inventorlogicblog.wordpress.com/2016/04/20/autodesk-inventor-ilogic-create-a-new-ilogic-rule-automatically/
'define the iLogic addin
Dim iLogicAddIn As ApplicationAddIn: Set iLogicAddIn = ThisApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
'get the iLogic automation object
Dim iLogic As Object: Set iLogic = iLogicAddIn.Automation
'get the list of iLogic rules in the current Inventor document
Dim RuleList As Object: Set RuleList = iLogic.Rules(Doc)
Dim RuleName As String: RuleName = "DummyInternalRule"
Dim RuleText As String: RuleText = ""
'loop through all rules in document
Dim Rule As Object
If Not (RuleList Is Nothing) Then
For Each Rule In RuleList
If StrComp(Rule.Name, RuleName, vbTextCompare) = 0 Then
If StrComp(Rule.Name, RuleName, vbTextCompare) = 0 Then
'a rule with the same name already exists...
Exit For
End If
End If
Next Rule
End If
If Not (Rule Is Nothing) Then
If OverWrite Then
'delete the existing rule
Call iLogic.DeleteRule(Doc, RuleName)
Else
Exit Function
End If
End If
'add the new rule
Call iLogic.AddRule(Doc, RuleName, RuleText)
End Function