Run ilogic external rule with Inventor VBA

Run ilogic external rule with Inventor VBA

Anonymous
Not applicable
4,618 Views
6 Replies
Message 1 of 7

Run ilogic external rule with Inventor VBA

Anonymous
Not applicable

Hello, everybody.

 

My problem is:

I want to run an existing ilogic external rule on Inventor VBA with no need of Event Triggers.

Could you help me, please?

0 Likes
Accepted solutions (1)
4,619 Views
6 Replies
Replies (6)
Message 2 of 7

Owner2229
Advisor
Advisor

Hi, you can try this one:

 

 

Private Sub RunRule()
RuniLogic ("C:\Path\MyRule.iLogicVb")
End Sub

Private Sub RuniLogic(ByVal RuleName As String)
Dim iLogicAuto As Object
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
If oDoc Is Nothing Then
MsgBox "Missing Inventor Document"
Exit Sub
End If
Set iLogicAuto = GetiLogicAddin(ThisApplication)
If (iLogicAuto Is Nothing) Then Exit Sub
iLogicAuto.RunExternalRule oDoc, RuleName
End Sub

Private Function GetiLogicAddin(oApplication As Inventor.Application) As Object
Set Addins = oApplication.ApplicationAddIns
Dim addIn As ApplicationAddIn
On Error GoTo NotFound
Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
If (addIn Is Nothing) Then Exit Function
addIn.Activate
Set GetiLogicAddin = addIn.Automation
Exit Function
NotFound:
End Function

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 7

Anonymous
Not applicable

Ok! It worked out, but only when the Subs were in the "DocumentProject".

When I tried to run the macro with the Subs on the "ApplicationProject (Default.ivb)" it didn't work out, even when I tried to run the macro in "All Application Projects and Active Documents".

 

Do you have any idea why did this happen?

How can I run this macro in any document?

Should I load another Project every time I open Inventor to make this work out?

Is there a way to keep more than one VBA project loaded when I launch Inventor?

0 Likes
Message 4 of 7

Owner2229
Advisor
Advisor

Hi, it might have been caused by protection... Try it again in "Default.ivb".

 

Public Sub RunRule()
    RuniLogic ("C:\Path\MyRule.iLogicVb")
End Sub

Public Sub RuniLogic(ByVal RuleName As String)
    Dim iLogicAuto As Object
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    If oDoc Is Nothing Then
        MsgBox "Missing Inventor Document"
        Exit Sub
    End If
    Set iLogicAuto = GetiLogicAddin(ThisApplication)
    If (iLogicAuto Is Nothing) Then Exit Sub
    iLogicAuto.RunExternalRule oDoc, RuleName
End Sub
 
Public Function GetiLogicAddin(oApplication As Inventor.Application) As Object
    Set Addins = oApplication.ApplicationAddIns
    Dim addIn As ApplicationAddIn
    On Error GoTo NotFound
    Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
    If (addIn Is Nothing) Then Exit Function
    addIn.Activate
    Set GetiLogicAddin = addIn.Automation
    Exit Function
NotFound:
End Function

 

Btw. Just in case you didn't know, you can use a ribbon button to run this code.

You can set up one like this:

 

1) Save your ApplicationProject and close "Microsoft Visual Basic For Application" window.

2) In Inventor in opened assembly or part go to "Tools" > "Customize"

3) In left tab expand the dropbox and select "Macros".

4) In right tab expand the dropbox and select "Assembly | Assembly"

5) In left tab select "RunRule".

6) Click on the arrows leading to right.

7) Click "Apply" and "Close".

8) In assembly go to "Assembly" tab and you should see there "User Commands". (On the right side of Ribbon)

9) The button should be there. Use it to run the code.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 5 of 7

Anonymous
Not applicable

When I tried to run the macro with the Subs on the "ApplicationProject (Default.ivb)" it didn't work out, even when I tried to run the macro in "All Application Projects and Active Documents".

 

Here's the messages of errorCapturar.PNGCapturar2.PNGp more than one VBA project loaded when I launch Inventor?

0 Likes
Message 6 of 7

Owner2229
Advisor
Advisor
Accepted solution

Hi, as Im looking at it now, the "error-line" does not need to be there.

About the project loading... I dont think you can specify more projects to be loaded at start. Inventor probably loads just the one specifed in Application Settings. It might be possible to start the other project(s) from the automaticaly loaded one with code.

 

Public Sub RunRule()
    RuniLogic ("C:\Path\MyRule.iLogicVb")
End Sub

Public Sub RuniLogic(ByVal RuleName As String)
    Dim iLogicAuto As Object
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument
    If oDoc Is Nothing Then
        MsgBox "Missing Inventor Document"
        Exit Sub
    End If
    Set iLogicAuto = GetiLogicAddin(ThisApplication)
    If (iLogicAuto Is Nothing) Then Exit Sub
    iLogicAuto.RunExternalRule oDoc, RuleName
End Sub
 
Public Function GetiLogicAddin(oApplication As Inventor.Application) As Object
    Dim addIn As ApplicationAddIn
    On Error GoTo NotFound
    Set addIn = oApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}")
    If (addIn Is Nothing) Then Exit Function
    addIn.Activate
    Set GetiLogicAddin = addIn.Automation
    Exit Function
NotFound:
End Function

 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 7 of 7

Anonymous
Not applicable

Yes!!! It's working Alright Now.

Thank you very much for help.

0 Likes