• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor Customization

    Reply
    Distinguished Contributor
    Lance_White
    Posts: 138
    Registered: ‎06-13-2011
    Accepted Solution

    Launch External iLogic rule with VBA

    1461 Views, 32 Replies
    09-26-2011 10:52 AM

    Is there someway to launch an external iLogic rule with VBA?. I'd like to add a button to run the iLogic rule.


    Lance W.
    Inventor Pro 2013 (PDS Ultimate)
    Vault Pro 2013
    Windows 7 64
    Xeon 2.4 Ghz 12GB
    Please use plain text.
    Valued Mentor
    Posts: 366
    Registered: ‎11-24-2003

    Re: Launch External iLogic rule with VBA

    09-26-2011 02:31 PM in reply to: Lance_White

    This has been answered before, but perhaps not exactly this way...

     

    --- In a VBA module ---

     

    Public Sub LaunchMyRule1   <--- This is what you would tie to a button in a toolbar.

      RuniLogic "MyRule1"

    End sub

     

    Public Sub LaunchMyRule2   <--- This is what you would tie to a button in a toolbar.

      RuniLogic "MyRule2"

    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

     

    Function GetiLogicAddin(oApplication As Inventor.Application) As Object
      Dim addIns As ApplicationAddIns
      Set addIns = oApplication.ApplicationAddIns

      Dim addIn As ApplicationAddIn
      Dim customAddIn As ApplicationAddIn
      For Each addIn In addIns
        If (addIn.ClassIdString = "{3BDD8D79-2179-4B11-8A5A-257B1C0263AC}") Then
          Set customAddIn = addIn
        Exit For
        End If
      Next

    Please use plain text.
    Distinguished Contributor
    Lance_White
    Posts: 138
    Registered: ‎06-13-2011

    Re: Launch External iLogic rule with VBA

    09-27-2011 10:50 AM in reply to: Gruff

    Thanks.


    Lance W.
    Inventor Pro 2013 (PDS Ultimate)
    Vault Pro 2013
    Windows 7 64
    Xeon 2.4 Ghz 12GB
    Please use plain text.
    Distinguished Contributor
    Lance_White
    Posts: 138
    Registered: ‎06-13-2011

    Re: Launch External iLogic rule with VBA

    10-03-2011 09:19 AM in reply to: Gruff

    I can't get this to work and I can't figure out what's wrong. I have looked around and the only other code I can find doesn't work either.

     

    Nevermind figured it out.

     

    Public Sub LaunchMyRule1   <--- This is what you would tie to a button in a toolbar.

      RuniLogic "MyRule1"

    End sub

     

    Public Sub LaunchMyRule2   <--- This is what you would tie to a button in a toolbar.

      RuniLogic "MyRule2"

    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

     

    Function GetiLogicAddin(oApplication As Inventor.Application) As Object
    Set addIns = oApplication.ApplicationAddIns

    'Find the add-in you are looking for
    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


    Lance W.
    Inventor Pro 2013 (PDS Ultimate)
    Vault Pro 2013
    Windows 7 64
    Xeon 2.4 Ghz 12GB
    Please use plain text.
    Contributor
    Posts: 21
    Registered: ‎09-01-2009

    Re: Launch External iLogic rule with VBA

    12-16-2011 04:59 AM in reply to: Lance_White

    Thanks a lot !

    It works for Inventor 2012 too.

     

    I just had to modify first line and add () :

     

     

    Public Sub LaunchMyRule1 ()

      RuniLogic "MyRule1"

    End sub

     

    ...

    Please use plain text.
    Mentor
    Posts: 306
    Registered: ‎02-11-2004

    Re: Launch External iLogic rule with VBA

    01-26-2012 11:48 AM in reply to: Lance_White

    Mike,

    I've tried using this in a VB6 program. I open up the part first that has the Rule I want to run, but I get an error saying it cannot find the external rule.

    The error occurs at iLogicAuto.RunExternalRule oDoc, RuleName.

    The RuleName is correct and the part does have a rule with the supplied name. Any suggestions?

    Mike Eck
    Senior Designer/ CAD Programmer
    Howden North America
    Using Inventor 2013
    Please use plain text.
    Contributor
    Posts: 21
    Registered: ‎09-01-2009

    Re : Launch External iLogic rule with VBA

    01-27-2012 05:09 AM in reply to: Lance_White

    Hello,

     

    This VBA Code is made to launch an external rule only.

    You have to link, in Inventor, an external iLogic rune, and not in the file.

    Please use plain text.
    Mentor
    Posts: 306
    Registered: ‎02-11-2004

    Re : Launch External iLogic rule with VBA

    01-31-2012 03:16 AM in reply to: idubail

    Thanks for the reply, but how do I do that?

    Mike Eck
    Senior Designer/ CAD Programmer
    Howden North America
    Using Inventor 2013
    Please use plain text.
    Mentor
    Posts: 306
    Registered: ‎02-11-2004

    Re : Launch External iLogic rule with VBA

    01-31-2012 12:57 PM in reply to: meck

    Never mind. I just had to change  

    iLogicAuto.RunExternalRule oDoc, RuleName

    to

     iLogicAuto.RunRule oDoc, RuleName

    Mike Eck
    Senior Designer/ CAD Programmer
    Howden North America
    Using Inventor 2013
    Please use plain text.
    Active Contributor
    varga_zsolt
    Posts: 41
    Registered: ‎09-15-2011

    Re: Launch External iLogic rule with VBA

    05-15-2012 08:14 AM in reply to: Lance_White

    I have Inventor pro 2012 but this code doesn't work! I need it can someone help me??????

    Please use plain text.