Run iLogic rule with VB.NET Plug-in, Part 2

Run iLogic rule with VB.NET Plug-in, Part 2

Daan_M
Collaborator Collaborator
756 Views
5 Replies
Message 1 of 6

Run iLogic rule with VB.NET Plug-in, Part 2

Daan_M
Collaborator
Collaborator

Hello again,

 

New post to keep things clean, I'm stuck on debugging my code. It stops at:

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

It shows the messagebox error 

 

 

see below a screenshot and also the window that comes up with the 'Exception thrown' when i stop debugging my code. Any idea what causes this?

error1.JPG

error2.JPG

 

Code in insterted(in case its easier to read this way)

Private Sub RuleRunner()
        Dim MyRuleName As String = "cmdRead"
        Dim iLogicAddinGuid As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
        Dim iLogicAddin As ApplicationAddIn
        Dim iLogicAutomation As IiLogicAutomation = 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
0 Likes
Accepted solutions (1)
757 Views
5 Replies
Replies (5)
Message 2 of 6

Daan_M
Collaborator
Collaborator

i added;

Catch ex As Exception

MsgBox(ex.Message) 

 

and it shows the following

error3.JPG

0 Likes
Message 3 of 6

LukeDavenport
Collaborator
Collaborator

Hi Daan,

Nearly there!

 

You need to use whatever reference you have to the Inventor application instead of _invApp in this line you currently have.

 

_invApp.ApplicationAddIns.ItemById(iLogicAddinGuid)

 

Where do you get that from? Well the Inventor application will probably be declared at the point that the addin is activated (normally this would be a sub called 'Activate' towards the top of your code) - it might be something like this in your code:

 

Dim InvApp As Inventor.Application = addInSiteObject.Application

 

So in the above case I could either pass the InvApp object to the sub that runs the iLogic rule, OR you could just create a global object for it (field or property of your class) so that you don't have to pass it to the sub.

 

Does that make sense?

Luke

0 Likes
Message 4 of 6

jelte.de.jong
Contributor
Contributor
Accepted solution

I did have the same problem when i started working with Automation properties of addins. The problem is that "iLogicAddin.Automation" always returns an object of the type "System.__ComObject". I never managed to cast it to something else like the type "IiLogicAutomation". but there is a solution just never cast it. That also means that you should not define the variable iLogicAutomation as the type IiLogicAutomation. try this code.

Dim MyRuleName As String = "cmdRead"
Dim iLogicAddinGuid As String = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}"
Dim iLogicAddin As ApplicationAddIn
Dim iLogicAutomation As Object = Nothing ' As IiLogicAutomation = Nothing

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

Try
    iLogicAutomation.RunRule(oDoc, MyRuleName)
Catch
    MessageBox.Show("There is no rule called " & MyRuleName)
End Try
Message 5 of 6

Daan_M
Collaborator
Collaborator

@jelte.de.jong and @LukeDavenport 

 

Thank you both so much, Jelte's tweak make the program work!

I'm really excited about this, i only discovered Inventor Automation with iLogic a month or two ago and i find it extremely intresting to see all the possibilities it offers. 

 

Thanks again for the help on these forums, resources for beginners are scarsce, so feedback from experienced users is very valuable.

 

0 Likes
Message 6 of 6

LukeDavenport
Collaborator
Collaborator

Thanks @jelte.de.jong.

 

I converted the code from C# to VB.net without checking it in an addin! That'll teach me.

Keep up the good work Daan.

Luke