Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Run external iLogic rule using macro

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
martinhoos
5480 Views, 10 Replies

Run external iLogic rule using macro

Hello all,

i am looking for a solution to run a external ilogic rule with yes/no out of a macro. I dont find any samples....  😞

 

Sub Stl_Export_LN()

If MsgBox("Möchtest Du eine Plausibilitaetsprüfung?", vbYesNo + vbQuestion) = vbYes Then
iLogicVb.RunExternalRule ("Plausibilitaetsprüfung")
End If

.........
End Sub

 

If the answer is yes, the ilogic shouldt be run and after that returns to the macro.

Hopeful this is possible.

Regards

Martin

10 REPLIES 10
Message 2 of 11
MechMachineMan
in reply to: martinhoos

Uhhhhh.....

 

https://forums.autodesk.com/t5/inventor-customization/launch-external-ilogic-rule-with-vba/td-p/3170...

 

From the link above, to run iLogic from VBA environment...

 

Public Sub LaunchMyRule1() '<--- "LaunchMyRule1" would be what shows up in the toolbar.
  RuniLogic "MyRule1"
End Sub

Public Sub LaunchMyRule2()
  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
  
  Set GetiLogicAddin = customAddIn
End Function

 

As an extra, to run VBA from iLogic, it looks something like this:

 

Dim invApp As Inventor.Application

invApp = ThisApplication

'To implement, you almost certainly need to change the indices (values in brackets) to match your code. invApp.VBAProjects(1).InventorVBAComponents("AppEventController").InventorVBAMembers("StartEvent").Execute

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 11

@MechMachineMan

 

That's nice information.

 

@martinhoos,

 

Try the below VBA code to run rule if the answer is yes.

 

Sub Stl_Export_LN()

If MsgBox("Möchtest Du eine Plausibilitaetsprüfung?", vbYesNo + vbQuestion) = vbYes Then
	RuniLogic ("Plausibilitaetsprüfung")
End If

.........
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
 
  Set GetiLogicAddin = customAddIn
End Function

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 4 of 11

Hi Chandra,

thanks for your reply. This code is like spanish to me - i dont understand  😞

Please, can you explain or Change the code for me  🙂

 

The Problem i have is a very old vba code, this code i have to Change with a question at the beginning. And if that question is answered with "yes" an external iLogic code shouldt runs... and after that the vba code shouldt finish... The old vba code is not that big - but i did not get change it to ilogic 😞

 

Hopefully you can hlep me....

 

Thank you in advance

Regards

Martin

Message 5 of 11

@martinhoos

 

Below VBA code is to get iLogic addin to run a rule by mentioning rule name.

 

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
  
  Set GetiLogicAddin = customAddIn
End Function

Below code is to run rule by calling above function RuniLogic. If the answer is Yes from message box.

 

Sub Stl_Export_LN()

If MsgBox("Möchtest Du eine Plausibilitaetsprüfung?", vbYesNo + vbQuestion) = vbYes Then
	RuniLogic ("Plausibilitaetsprüfung")
End If

.........
End Sub

Please feel free to contact if there is any queries.

 

If solves problem, click on "Accept as solution" / give a "Kudo".

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 6 of 11
MechMachineMan
in reply to: martinhoos

@martinhoos You cannot make the program jump between 2 rules concurrently.

 

Your best option here is to have the iLogic rule that I (and @chandra.shekar.g) posted run as your main vba rule, and embed the question within it, and then run the iLogic rule from it as needed.

 

If you have the question built into the external rule, just have the VBA fire the rule and DO NOT put the question in the VBA as it already exists in the rule.

 

If you would post more of your code, perhaps we could rewrite it or explain it better for you.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 7 of 11


@MechMachineMan wrote:

 

As an extra, to run VBA from iLogic, it looks something like this:

 

Dim invApp As Inventor.Application

invApp = ThisApplication

'To implement, you almost certainly need to change the indices (values in brackets) to match your code. invApp.VBAProjects(1).InventorVBAComponents("AppEventController").InventorVBAMembers("StartEvent").Execute

 

From iLogic you can also just use this line to call a VBA macro

 

	'call VBA Macro
    InventorVb.RunMacro("ApplicationProject", "Module1", "MyMacro")

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

Message 8 of 11

Hi all, thanks again for your replies. This will help me.

Regards Martin

Message 9 of 11
JasonMayes
in reply to: martinhoos

this part is giving me fits. it errors out. it is probably something simple... any help?

 

Capture.JPG

Message 10 of 11

I have the same problem...and I just need a simple marco to start one ilogic rule

Message 11 of 11

Without to much work I was able to manipulate the code found here and get it to work.

https://www.cadlinecommunity.co.uk/hc/en-us/articles/115000859309-Inventor-Run-iLogic-Rules-from-you...

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report