Inventor Customization

Inventor Customization

Reply
Member
mziegler
Posts: 5
Registered: ‎10-24-2007
Message 1 of 4 (1,180 Views)

iLogic run rule vb.net

1180 Views, 3 Replies
10-29-2010 01:55 AM

Hello, 

 

I have recently started to write inventor addins in vb.net.

 At the moment try a iLogic rule call. But i cant find an vb.net-example for this here or anywhere else.


I created the rule and now i want to run it.

 

1530i3A1E1D356BCF17FB

 

I would be very happy if someone could help me with this problem!


Valued Contributor
herrwolf1
Posts: 54
Registered: ‎08-21-2008
Message 2 of 4 (1,164 Views)

Re: iLogic run rule vb.net

10-29-2010 06:10 AM in reply to: mziegler

Hello,

   It's not as simple as just running the rule. The following code should get you what you need. I use this code in a third party VB.Net 2008 app. It should work for an addin. I hope this helps.

 

 

Private iLogicAuto As Object
Private invApp As Inventor.Application

Public Sub RuniLogicRule(ByVal RuleName As String)
On Error Resume Next

If iLogicAuto Is Nothing Then
iLogicAuto = GetiLogicAutomation(invApp)
End If

If iLogicAuto Is Nothing Then Exit Sub

Dim oDoc As Inventor.Document = invApp.ActiveDocument

iLogicAuto.RunRule(oDoc, RuleName)
oDoc = Nothing

On Error GoTo 0
End Sub

Private Function GetiLogicAutomation(ByVal oApplication As Inventor.Application) As Object
'Get the addins collection
Dim addIns As ApplicationAddIns
addIns = oApplication.ApplicationAddIns

'Find the add-in you are looking for
Dim customAddIn As ApplicationAddIn = Nothing
Dim i As Long
For i = 1 To addIns.Count
If (addIns(i).ShortDisplayName = "iLogic") Then
customAddIn = addIns.Item(i)
Exit For
End If
Next i

If (customAddIn Is Nothing) Then Return Nothing

customAddIn.Activate()
GetiLogicAutomation = customAddIn.Automation
End Function

RuniLogicRule("Update Title Block Rule")

 

 

 

Contributor
jvolence
Posts: 22
Registered: ‎11-16-2009
Message 3 of 4 (460 Views)

Re: iLogic run rule vb.net

10-25-2013 08:27 AM in reply to: mziegler

I tried running this with vb.net 2013 and it desn't do anything (doesn't run the rule).

 

It seems like when it runs the GetIlogicAutomation sub, it does not return the ilogic object... because if I test the value of ilogicauto after it runs that sub, the value is still Nothing. 

 

It also seems that the invapp object isn't being assigned anything?  I am used to doing "invapp=thisapplication" after the dim statement, but vb.net says that "thisapplication" is not declared. 

 

Here is what I have as a class library to call from ilogic itself:

 

Imports Inventor

Public Class InventorAPI

    Private iLogicAuto As Object = Nothing
    Private invApp As Inventor.Application

    Public Sub RuniLogicRule(ByVal RuleName As String)
        On Error Resume Next
        invApp = Application
        If iLogicAuto Is Nothing Then
            iLogicAuto = GetiLogicAutomation(invApp)
        End If

        If iLogicAuto Is Nothing Then Exit Sub

        Dim oDoc As Inventor.Document = invApp.ActiveDocument

        iLogicAuto.RunRule(oDoc, RuleName)
        oDoc = Nothing

        On Error GoTo 0
    End Sub

    Function ReadInvParam(ParamName As String) As String
        On Error Resume Next

        'If iLogicAuto Is Nothing Then
        iLogicAuto = GetiLogicAutomation(invApp)
        'End If

        If iLogicAuto Is Nothing Then Return "Unable to get Ilogic object"

        Dim oDoc As Inventor.Document = invApp.ActiveDocument

        Return iLogicAuto.ParamValue(oDoc, ParamName)
    End Function

    Private Function GetiLogicAutomation(ByVal oApplication As Inventor.Application) As Object
        'Get the addins collection
        Dim addIns As ApplicationAddIns
        addIns = oApplication.ApplicationAddIns

        'Find the add-in you are looking for
        Dim customAddIn As ApplicationAddIn = Nothing
        Dim i As Long
        For i = 1 To addIns.Count
            MsgBox(addIns(i))
            If (addIns(i).ShortDisplayName = "iLogic") Then
                customAddIn = addIns.Item(i)
                Exit For
            End If
        Next i

        If (customAddIn Is Nothing) Then Return Nothing

        customAddIn.Activate()
        GetiLogicAutomation = customAddIn.Automation
        Return customAddIn.Automation
    End Function
End Class

 

I am then calling that library with:

 

AddReference "C:\_Vaultwip\vb_addons\InventorAPI.dll"
Dim oLib As New InventorAPI.InventorAPI

MessageBox.Show(oLib.ReadInvParam("test"))
Call oLib.RuniLogicRule("myRule")

 and what I get is that it cannot get the ilogic object, and then nothing. 

 

Thanks!

 

Valued Mentor
rjay75
Posts: 362
Registered: ‎04-14-2005
Message 4 of 4 (454 Views)

Re: iLogic run rule vb.net

10-25-2013 09:48 AM in reply to: jvolence

I've actually done something similar to this in C#. You need to assign the Inventor reference to you library.

 

In your class constructor I would pass the current Inventor Application object to the library like so.

 

Public Class InventorAPI

    Private iLogicAuto As Object = Nothing
    Private invApp As Inventor.Application

    Public Sub New(ByRef app As Inventor.Application)
      'Set the app to the app supplied by the rule
      invApp = app
      'Set the iLogic Automation
      iLogicAuto = invApp.ApplicationAddins.ItemsById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}").Automation
    End Sub

    Public Sub RuniLogicRule(ByVal RuleName As String)
        On Error Resume Next

Dim oDoc As Inventor.Document = invApp.ActiveDocument iLogicAuto.RunRule(oDoc, RuleName) oDoc = Nothing On Error GoTo 0 End Sub Function ReadInvParam(ParamName As String) As String On Error Resume Next Return iLogicAuto.ParamValue(oDoc, ParamName) End Function End Class

 

In the iLogic rule

AddReference "C:\_Vaultwip\vb_addons\InventorAPI.dll"
Dim oLib As New InventorAPI.InventorAPI(ThisApplication)

MessageBox.Show(oLib.ReadInvParam("test"))
Call oLib.RuniLogicRule("myRule")

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.