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.
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.
Seems I have made an absolute beginner mistake. Sorry to bother you all 🙂
For some strange reason the target framework is suddenly .NET 5.0 and I'm unable to select 4.7.2 even if it's installed on my computer. I had to open an old project and copy-paste the code into an already existing 4.7.2 solution. Now it works, however I now need to figure out why all my new projects have only .NET 5.0 as a valid choice.
Seems I have made an absolute beginner mistake. Sorry to bother you all 🙂
For some strange reason the target framework is suddenly .NET 5.0 and I'm unable to select 4.7.2 even if it's installed on my computer. I had to open an old project and copy-paste the code into an already existing 4.7.2 solution. Now it works, however I now need to figure out why all my new projects have only .NET 5.0 as a valid choice.
I know you said that you think you have got it figured out, but thought I would still include a few links here, just in case these may help some. These links are from Inventor's online help area, and point the way to the RunExternalRule method you were trying to use.
Autodesk.iLogic.Interfaces Namespace
IiLogicAutomation.RunExternalRule Method
And from an iLogic rule, we would get to this point this way:
i = iLogicVb.Automation.RunExternalRule(oDoc, oRuleName)
Where 'iLogicVb' represents 'ILowLevelSupport' (an Interface), 'Automation' represents 'IiLogicAutomation' (a ReadOnly Property that represents an Interface).
So the longer way that code could be represented in an iLogic rule could look like this:
Dim iLogic As ILowLevelSupport = iLogicVb
Dim oAutomation As IiLogicAutomation = iLogic.Automation
oAutomation.RunExternalRule(oDoc, oRuleName)
I know you are using straight VB.net, so you won't be able to use these codes directly, but I'm thinking that the information above might contain some useful information and hints that might help either for you, or others who may look at this later.
Wesley Crihfield
(Not an Autodesk Employee)
I know you said that you think you have got it figured out, but thought I would still include a few links here, just in case these may help some. These links are from Inventor's online help area, and point the way to the RunExternalRule method you were trying to use.
Autodesk.iLogic.Interfaces Namespace
IiLogicAutomation.RunExternalRule Method
And from an iLogic rule, we would get to this point this way:
i = iLogicVb.Automation.RunExternalRule(oDoc, oRuleName)
Where 'iLogicVb' represents 'ILowLevelSupport' (an Interface), 'Automation' represents 'IiLogicAutomation' (a ReadOnly Property that represents an Interface).
So the longer way that code could be represented in an iLogic rule could look like this:
Dim iLogic As ILowLevelSupport = iLogicVb
Dim oAutomation As IiLogicAutomation = iLogic.Automation
oAutomation.RunExternalRule(oDoc, oRuleName)
I know you are using straight VB.net, so you won't be able to use these codes directly, but I'm thinking that the information above might contain some useful information and hints that might help either for you, or others who may look at this later.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @brnQSMNT in the projects properties in visual studio, you should be able to select the specific .NET framework you are working with. (Right click the project in solution explorer then go to applications, target framework)
Hi @brnQSMNT in the projects properties in visual studio, you should be able to select the specific .NET framework you are working with. (Right click the project in solution explorer then go to applications, target framework)
Can't find what you're looking for? Ask the community or share your knowledge.