Is there someway to launch an external iLogic rule with VBA?. I'd like to add a button to run the iLogic rule.
Solved! Go to Solution.
Solved by Lance127. Go to Solution.
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
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
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
...
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?
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.
Never mind. I just had to change
iLogicAuto.RunExternalRule oDoc, RuleName
to
iLogicAuto.RunRule oDoc, RuleName
Have you created an external Rule file?
The code posted is for External rules only. If your rule is inside the inventor document you cannot use this method..
I fave the esternel rule called DXF_PDF_zsolt and in VBA i have this code:
Public Sub DXF_PDF_Creator() RuniLogic "DXF_PDF_zsolt" 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
if you put a break in your VBA code at
"RuniLogic "DXF_PDF_zsolt"
Run the VBA code and step through the code one line at a time with F8 where does it fail?
PS. Why are you using an iLogic to creare a PDF? You can do it all in VBA.
When i tun the vba conde step by step with F8 in works fine. There is no errer, but it don't execute the external rule! When you tun the vba code he don't do nothing.
I use ilogic because i don't be able to do this in vba.
This is my ilogic rule:
' Percorsi dove veranno salvati il DXF e il PDF oPath = "C:\Users\varga\Desktop\" PN = iProperties.Value("Project", "Part Number") ' Get the DXF translator Add-In. Dim DXFAddIn As TranslatorAddIn DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}") 'Set a reference to the active document (the document to be published). Dim oDocument As Document oDocument = ThisApplication.ActiveDocument Dim oContext As TranslationContext oContext = ThisApplication.TransientObjects.CreateTranslationContext oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism ' Create a NameValueMap object Dim oOptions As NameValueMap oOptions = ThisApplication.TransientObjects.CreateNameValueMap ' Create a DataMedium object Dim oDataMedium As DataMedium oDataMedium = ThisApplication.TransientObjects.CreateDataMedium ' Check whether the translator has 'SaveCopyAs' options If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then Dim strIniFile As String strIniFile = "Z:\Autodesk\Inventor2012\iLogic_Rules\fornitori.ini" ' Create the name-value that specifies the ini file to use. oOptions.Value("Export_Acad_IniFile") = strIniFile End If 'Set the destination file name oDataMedium.FileName = oPath & "\" & PN & ".dxf" 'Publish document. DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium) 'Crea il File PDF oPrintMgr = ThisApplication.ActiveDocument.PrintManager oPrintMgr.Printer = "Adobe PDF" oPrintMgr.ColorMode = kPrintGrayScale 'oPrintMgr.ColorMode = kPrintColorPalette oPrintMgr.NumberOfCopies = 1 oPrintMgr.Orientation = kPortraitOrientation 'oPrintMgr.Orientation = kLandscapeOrientation oPrintMgr.PaperSize = kPaperSizeA4 oPrintMgr.SubmitPrint 'Chiede se vuoi aprire il DXF appena creato i = MessageBox.Show("Vuoi aprire il file DXF appena creato?", "Anteprima",MessageBoxButtons.YesNo,MessageBoxIcon.Question) If i = vbYes Then ThisDoc.Launch(oDataMedium.FileName)
At a glance that code looks like it should work in VBA just fine. You might have to set a few variables but otherwise you are pretty much where you need to be. I am swamped at the today. Give me some time and I will update it to be VBA code.
Okay,
Here is a VBA version of your code.
I broke it up into two sub routines.
1) The main sub routine that gets the filename and calls the translators.
2) The Translator Sub Routine
I commented out your code that uses the printer to create a PDF and used
the built in PDF Translator Addin.
Give it a try AS IS.
If you want to get back your Printer PDF Code it is still there.
You just need to uncomment the Printer Code and comment the PDF Translator Code.
Have Fun
--- Code Attached below .---
Can't find what you're looking for? Ask the community or share your knowledge.