Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trigger iLogic Rule from VB, Inventor 2021

3 REPLIES 3
Reply
Message 1 of 4
brnQSMNT
572 Views, 3 Replies

Trigger iLogic Rule from VB, Inventor 2021

brnQSMNT
Explorer
Explorer

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

brnQSMNT_2-1641890813212.png

 

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:

brnQSMNT_3-1641891051860.png

 

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.

 

0 Likes

Trigger iLogic Rule from VB, Inventor 2021

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

brnQSMNT_2-1641890813212.png

 

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:

brnQSMNT_3-1641891051860.png

 

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.

 

Labels (2)
3 REPLIES 3
Message 2 of 4
brnQSMNT
in reply to: brnQSMNT

brnQSMNT
Explorer
Explorer

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.

0 Likes

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.

Message 3 of 4
WCrihfield
in reply to: brnQSMNT

WCrihfield
Mentor
Mentor

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 Interface 

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

EESignature

(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 Interface 

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

EESignature

(Not an Autodesk Employee)

Message 4 of 4

fidel.makatiaD5W7V
Alumni
Alumni

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)



Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |
0 Likes

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)



Fidel Makatia
Developer Advocate

href=https://help.autodesk.com/view/INVNTOR/2022/ENU/?guid=GUID-0BD48573-7193-4285-87B7-6727555D053E rel= "noopener noreferrer">Inventor 2022 Documentation |

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report