Run iLogic rule by VB.NET plug-in

Run iLogic rule by VB.NET plug-in

Daan_M
Collaborator Collaborator
2,667 Views
7 Replies
Message 1 of 8

Run iLogic rule by VB.NET plug-in

Daan_M
Collaborator
Collaborator

Hi Forum,

 

I've made a program in Microsoft Visual Studio using VB.NET that starts Inventor and opens a specific assembly document, this works fine so far. Now i want to run a rule inside this assembly document, i tried looking up some code examples but i dont fully understand them and i cant get them to work.

 

This is where i am at right now;

Imports System
Imports System.Type
Imports System.Activator
Imports System.Runtime.InteropServices
Imports Inventor

Public Class Form1
'My current dims (used in Private Sub Launch&Open)

'Private Sub Launch&Open (launching inventor and opens assembly doc)
'code
'End Sub

'Private Sub RunRule (for running rule inside my doc)
'????
'End Sub

 

I don't know what code i can use to run the rule, see the '????' above. Can anyone take me through the steps or maybe show some exampe code? 

 

If more resources are needed from my side let me know, thanks!

0 Likes
Accepted solutions (2)
2,668 Views
7 Replies
Replies (7)
Message 2 of 8

LukeDavenport
Collaborator
Collaborator
Accepted solution

Hi Daan,

This should work in VB.Net. Obviously you'll need to make sure you're pointing at the right Inventor document and rule name.

Kind regards,
Luke

 

   Dim MyRuleName As String = "Rule0"
    Dim Doc As Inventor.Document = ThisApplication.ActiveEditDocument
    Dim iLogicAddinGuid As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
    Dim iLogicAddin As ApplicationAddIn = Nothing
    Dim iLogicAutomation As IiLogicAutomation = Nothing

    Try
        iLogicAddin = ThisApplication.ApplicationAddIns.ItemById(iLogicAddinGuid)
        iLogicAutomation = iLogicAddin.Automation
    Catch
        MessageBox.Show("Unable to access iLogic addin")
    End Try

    Try
        iLogicAutomation.RunRule(Doc, MyRuleName)
    Catch
        MessageBox.Show("There is no rule called " & MyRuleName)
    End Try

 

Message 3 of 8

Daan_M
Collaborator
Collaborator

Hi Luke, 

 

Firstly, thank you! This is what i was looking for. After putting it in my program i still have a error in line;

 

 Dim iLogicAutomation As IiLogicAutomation = Nothing

 

 

Error sais; 
Error BC30451 'IiLogicAddin' is not declared. It may be inaccessible due to its protection level.  C:\Users\daanm\Desktop\InventorPlugin\Basis\BasisLaunchCode.vb 61 Active
Error BC30002 Type 'iLogicAutomation' is not defined. C:\Users\daanm\Desktop\InventorPlugin\Basis\BasisLaunchCode.vb 57 Active

 

Error BC30451 is just a typo, so easy fix.

Error BC30002 i cant seem to fix? it still sais that Type is not defined

 

Below is the code adjusted to my program, adjustment;

1. Changed MyRuleName to "cmdRead"

2. Removed Dim Doc since i had it previously declared for earlier code as oDoc

 

 

 

 

 Private Sub RuleRunner()
        Dim MyRuleName As String = "cmdRead"
        Dim iLogicAddinGuid As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
        Dim iLogicAddin As ApplicationAddIn = Nothing
        Dim iLogicAutomation As iLogicAutomation = Nothing

        Try
            iLogicAddin = _invApp.ApplicationAddIns.ItemById(iLogicAddinGuid)
            iLogicAutomation = iLogicAddin.Automation
        Catch
            MessageBox.Show("Unable to access iLogic addin")
        End Try

        Try
            iLogicAutomation.RunRule(oDoc, MyRuleName)
        Catch
            MessageBox.Show("There is no rule called " & MyRuleName)
        End Try
    End Sub
End Class

 

 

 

 

 

 

0 Likes
Message 4 of 8

LukeDavenport
Collaborator
Collaborator
Accepted solution

You need to add a reference to Autodesk.iLogic.Interfaces.dll. See the below Autodesk extract:

 

Use iLogic Interfaces in External DLLs

All iLogic functions are grouped under interface objects such as Parameter, iProperties, iPart, and so on. You can pass iLogic interface objects as arguments to functions in external DLLs. To use these objects in your project, add a reference to Autodesk.iLogic.Interfaces.dll. Select the Browse tab in the Add Reference dialog box, and browse to the iLogicBin folder, under the Inventor bin folder (usually in C:\Program Files\Autodesk\Inventor [Version]\Bin\iLogicBin).

Message 5 of 8

Daan_M
Collaborator
Collaborator

Thanks, after adding the reference the code i can build. When executing the MsgBox pops up from lines;

 

Catch
MessageBox.Show("Unable to access iLogic addin")

 

So im assuming something doesn't work in; 

 

Try
iLogicAddin = _invApp.ApplicationAddIns.ItemById(iLogicAddinGuid)
iLogicAutomation = iLogicAddin.Automation

 

I get the following warning message:

 

Severity Code Description Project File Line Suppression State
Warning BC40059 A reference was created to embedded interop assembly 'Autodesk.Inventor.Interop, Version=25.0.0.0, Culture=neutral, PublicKeyToken=d84147f8b4276564' because of an indirect reference to that assembly from assembly 'Autodesk.iLogic.Interfaces, Version=25.0.18300.0, Culture=neutral, PublicKeyToken=null'. Consider changing the 'Embed Interop Types' property on either assembly. 

 

From reading the error im guessing it something to do with ; 'Autodesk.Inventor.Interop.dll' that i added earlier in my project, i suppose it conflicts because the newly added reference to 'Autodesk.iLogic.Interfaces.dll'. 

Because both these '.dll' are referenced in a differet way? direct and indirect? one is embedded and the other is not? I'm trying to get a better understanding of what this means, i'm new to coding.

 

Thanks again

  

 

 

 

0 Likes
Message 6 of 8

LukeDavenport
Collaborator
Collaborator

Oh whoops sorry, think you'll need to replace

_invApp.ApplicationAddIns.ItemById(iLogicAddinGuid)

with

ThisApplication.ApplicationAddIns.ItemById(iLogicAddinGuid)

 Does that work?

Luke

0 Likes
Message 7 of 8

Daan_M
Collaborator
Collaborator

It doesn't work because i haven't declared or used ThisApplication anywhere before.

 

I googled and found the following:

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/error-messages/bc40059

 

they suggest;

"To address this warning
To embed interop type information for both assemblies, set the Embed Interop Types property on all references to assembly1 to True."

 

Maybe this will help solve it, I however don't exactly know how to do this haha

 

 

 

 

0 Likes
Message 8 of 8

Daan_M
Collaborator
Collaborator

@LukeDavenport i changed the embed to false, i get no more Errors or Warnings now. However the iLogicAddins still cantbe accessed.  I think the cause might be some newbie mistake i made in my code, are you willing to take a look at it? i can send it through dm

  •  
0 Likes