Run an internal iLogic Rule from VB.net

Run an internal iLogic Rule from VB.net

BromanSillito
Advocate Advocate
3,674 Views
4 Replies
Message 1 of 5

Run an internal iLogic Rule from VB.net

BromanSillito
Advocate
Advocate

I'm trying to get my VB.net program to run internal iLogic rules. I've done a lot of searching on the web & in these forums but still can't seem to make my program work. Here's the current module that I'm trying to get working:

 

Imports Inventor

Imports System.IO

Module modiLogic

Private iLogicAuto As Object

Private invApp As Inventor.Application

Public Sub RuniLogicRule(ByVal RuleName As String)

On Error Resume Next

iLogicAuto = GetiLogicAddin(invApp)

 

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 GetiLogicAddin(oApplication As Inventor.Application) As Object

' Get addin collection & addin variables

GetiLogicAddin = Nothing

Dim addIns As ApplicationAddIns = oApplication.ApplicationAddIns

Dim addIn As ApplicationAddIn

Dim customAddIn As ApplicationAddIn = Nothing

For Each addIn In addIns

If (addIn.ClassIdString = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") Then

customAddIn = addIn

Exit For

End If

Next

If (customAddIn Is Nothing) Then

Exit Function

Else

customAddIn.Activate()

Return customAddIn.Automation

End If

End Function

End Module

 

 

Here is an internal iLogic rule I am trying to run from VB.net:

 

If FlgType = "RF Weld-Neck Flange" Then
FlgStBk = Parameter("SHELL_FLG", "Y") + Parameter("SHELL_FLG", "RF") + WeldGap

ElseIf FlgType = "RJ Weld-Neck Flange" Then
FlgStBk = Parameter("SHELL_FLG", "Y") + Parameter("SHELL_FLG", "RF") + WeldGap


ElseIf FlgType = "RF Slip-On Flange" Then
inc = .0625 ' rounding increment ( .125, .25, .5, etc)
FlgStBk = Ceil(Round(Parameter("SHELL_PIPE", "t") + .0625,4) / inc) * inc

ElseIf FlgType = "RJ Slip-On Flange" Then
inc = .0625 ' rounding increment ( .125, .25, .5, etc)
FlgStBk = Ceil(Round(Parameter("SHELL_PIPE", "t") + .0625,4) / inc) * inc



End If


InventorVb.DocumentUpdate()

 

Here is how I'm calling out the sub:

 

Private Sub btnTestiLogic_Click(sender As Object, e As EventArgs) Handles btnTestiLogic.Click

CheckInventor()

RuniLogicRule("ShellPipeSize")

End Sub

 

When I press the "btnTestiLogic" button, nothing happens.

 

Could somebody please give me some advice to help fix this?

 

0 Likes
Accepted solutions (1)
3,675 Views
4 Replies
Replies (4)
Message 2 of 5

Owner2229
Advisor
Advisor
Accepted solution

HI, here below is the VB.Net code I'm ussing:

 

 

Imports Inventor
Imports System.Runtime.InteropServices

Public Class RunRule
Private InventorApplication As Inventor.Application

Public Sub iLogic(rule As String)
Try
InventorApplication = Marshal.GetActiveObject("Inventor.Application")
Catch
Exit Sub
End Try
Dim iLogicAuto As Object Dim oDoc As Inventor.Document oDoc = InventorApplication.ActiveDocument If oDoc Is Nothing Then MsgBox ("Missing Inventor Document") Exit Sub End If iLogicAuto = GetiLogicAddin() If (iLogicAuto Is Nothing) Then Exit Sub iLogicAuto.RunExternalRule(oDoc, rule) End Sub Private Function GetiLogicAddin() As Object Dim addIn As Inventor.ApplicationAddIn Try addIn = InventorApplication.ApplicationAddIns.ItemById("{3bdd8d79-2179-4b11-8a5a-257b1c0263ac}") addIn.Activate GetiLogicAddin = addIn.Automation Catch GetiLogicAddin = Nothing End Try End Function
End Class

 

You can the use it like this:

 

Dim Run As New RunRule
Run.iLogic("ShellPipeSize")
Run = Nothing
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 3 of 5

BromanSillito
Advocate
Advocate

Thanks Owner2229. I copied the code over to it's own class but it isn't working - nothing happens when I run it. Here's how I'm calling it out:

 

Private Sub btnTestiLogic_Click(sender As Object, e As EventArgs) Handles btnTestiLogic.Click

CheckInventor()

Dim Run As New RunRule

Run.iLogic("Testing")

Run = Nothing

End Sub

 

I'm using a button in a form (btnTestiLogic) that I press to run the code. When I try to debug, it looks to me like it is hitting the "If (iLogicAuto Is Nothing)" statement and ilogicAuto is returning Nothing so it is exiting the sub before it can run the rule. Any ideas why iLogicAuto is not working? 

0 Likes
Message 4 of 5

Owner2229
Advisor
Advisor

Hi, I can't see why it wouldn't work :S

 

Do you have added the references for both "Autodesk.Inventor.Interops" and "System" ?

 

Maybe you can try this, as you actualy sayd you want to run an internal rule:

 

iLogicAuto.RunRule(oDoc, rule)

instead of this:

 

iLogicAuto.RunExternalRule(oDoc, rule)

 

Anyway, what stops you from rewriting the iLogic rule to your VB.Net program?

 

This is how you can acces the parameters from VB.Net. E.g. if I want to set the parameter "size" to be 25:

 

Imports Inventor

Private InventorApplication As Inventor.Application

Sub Main()
Try
InventorApplication = Marshal.GetActiveObject("Inventor.Application")
Catch
Exit Sub
End Try
Dim oDoc As Inventor.Document
oDoc = InventorApplication.ActiveDocument
oParameter(oDoc, "size").Expression = 25
End Sub

Private Function oParameter(oDoc As Inventor.PartDocument, oPara As String) As Inventor.Parameter Dim oParams As Inventor.Parameters oParams = oDoc.ComponentDefinition.Parameters oParameter = oParams.Item(oPara) 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 5 of 5

JBEDsol
Collaborator
Collaborator

When I get into creating classes that's straight over my head.  How/where do I enter the class code?

0 Likes