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
Solved! Go to Solution.
Solved by MechMachineMan. Go to Solution.
Solved by chandra.shekar.g. Go to Solution.
Uhhhhh.....
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
That's nice information.
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,
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
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,
@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.
@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
this part is giving me fits. it errors out. it is probably something simple... any help?
I have the same problem...and I just need a simple marco to start one ilogic rule
Without to much work I was able to manipulate the code found here and get it to work.
Can't find what you're looking for? Ask the community or share your knowledge.