Launch External iLogic rule with VBA

Lance127
Advocate
Advocate

Launch External iLogic rule with VBA

Lance127
Advocate
Advocate

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
0 Likes
Reply
Accepted solutions (2)
23,996 Views
39 Replies
Replies (39)

Anonymous
Not applicable
Accepted 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

Lance127
Advocate
Advocate

Thanks.


Lance W.
Inventor Pro 2013 (PDS Ultimate)
Vault Pro 2013
Windows 7 64
Xeon 2.4 Ghz 12GB
0 Likes

Lance127
Advocate
Advocate
Accepted solution

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

Anonymous
Not applicable

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

 

...

meck
Collaborator
Collaborator

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
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes

Anonymous
Not applicable

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.

0 Likes

meck
Collaborator
Collaborator

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

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes

meck
Collaborator
Collaborator

Never mind. I just had to change  

iLogicAuto.RunExternalRule oDoc, RuleName

to

 iLogicAuto.RunRule oDoc, RuleName

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
0 Likes

Anonymous
Not applicable

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

0 Likes

Anonymous
Not applicable

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..

0 Likes

Anonymous
Not applicable

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

 

 

0 Likes

Anonymous
Not applicable

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.

0 Likes

Anonymous
Not applicable

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)

 

 

 

0 Likes

Anonymous
Not applicable

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.

0 Likes

Anonymous
Not applicable
Thank you very much you will give me a big hand!! 😉 I'am waiting for you. Thanks a lot!
0 Likes

Anonymous
Not applicable

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 .---

0 Likes

Anonymous
Not applicable
Thank you very very much! As soon as possible I test this code and I let you know how it works.
P.s. I use the adobe PDF printer and not the integrated PDF creator because sometime the integrated creator do the error in text parts of the drawings I don't know why! With adobe I never have problem.
0 Likes

Anonymous
Not applicable

I've tray to execute the VBA code but it give me this error:

img.jpg

0 Likes

Anonymous
Not applicable

I don't be able to find the error.

 

P.s. I need only adobe PDF script not the netive PDF creator.

0 Likes