Trigger iLogic Rule from VB, Inventor 2021
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Having googled and searched for days on end I've come across many posts with this question and all seems to be answered by one of two similar solutions. I've tried every variant of the answers, and even tried to combine them somehow, but always ends up short of a working solution.
The first solution is by far the one I found most often as the answer, but I must be missing something obvious here. I've also been able to confirm that this worked at least as late as Inventor 2018.
Dim iLogicAuto As Object
iLogicAuto = addin.Automation
iLogicAuto.RunExternalRule(oDoc, "RuleName")
Error on the last of the 3 lines
The second solution is something I found as a C# solution and tried to convert to VB, but it probably needs some kind of typecasting, which I don't know how to do, or even if it is possible in VB:
Dim iLogicAuto As iLogicAutomation
iLogicAuto = addin.Automation
iLogicAuto.RunExternalRule(oDoc, "RuleName")
Error on the second of the 3 lines:
In the full example below I've included both, but commented out one of them. This is part of a larger code, but I have isolated the lines below for testing as they are all that seems to be needed for this particular issue.
Imports System.IO
Imports Inventor
Imports Autodesk.iLogic.Automation
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim oApp As Application
Dim InventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")
oApp = System.Activator.CreateInstance(InventorAppType)
oApp.Visible = True
Dim Filename As String = "C:\Inventor\Test.iam"
Dim oDoc As AssemblyDocument = oApp.Documents.Open(Filename, True)
' Pause for 30 seconds
System.Threading.Thread.Sleep(30000)
Dim addin As ApplicationAddIn
addin = oApp.ApplicationAddIns.ItemById("{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}")
addin.Activate()
Dim iLogicAuto As Object
iLogicAuto = addin.Automation
iLogicAuto.RunExternalRule(oDoc, "RuleName")
'Dim iLogicAuto As iLogicAutomation
'iLogicAuto = addin.Automation
'iLogicAuto.RunExternalRule(oDoc, "RuleName")
Close()
End Sub
End Class
Inventor starts up and loads the correct template, but the rule fails. Any help would be much appreciated.