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: 

Launch External iLogic rule with VBA

39 REPLIES 39
SOLVED
Reply
Message 1 of 40
Lance127
24005 Views, 39 Replies

Launch External iLogic rule with VBA

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
39 REPLIES 39
Message 2 of 40
Anonymous
in reply to: Lance127

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

Message 3 of 40
Lance127
in reply to: Anonymous

Thanks.


Lance W.
Inventor Pro 2013 (PDS Ultimate)
Vault Pro 2013
Windows 7 64
Xeon 2.4 Ghz 12GB
Message 4 of 40
Lance127
in reply to: Anonymous

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
Message 5 of 40
Anonymous
in reply to: Lance127

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

 

...

Message 6 of 40
meck
in reply to: Lance127

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
Message 7 of 40
Anonymous
in reply to: Lance127

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.

Message 8 of 40
meck
in reply to: Anonymous

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

Mike Eck
Master Drafter/ CAD Programmer
Using Inventor 2018
Message 9 of 40
meck
in reply to: meck

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
Message 10 of 40
Anonymous
in reply to: Lance127

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

Message 11 of 40
Anonymous
in reply to: Lance127

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

Message 12 of 40
Anonymous
in reply to: Anonymous

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

 

 

Message 13 of 40
Anonymous
in reply to: Anonymous

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.

Message 14 of 40
Anonymous
in reply to: Anonymous

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)

 

 

 

Message 15 of 40
Anonymous
in reply to: Anonymous

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.

Message 16 of 40
Anonymous
in reply to: Lance127

Thank you very much you will give me a big hand!! 😉 I'am waiting for you. Thanks a lot!
Message 17 of 40
Anonymous
in reply to: Anonymous

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

Message 18 of 40
Anonymous
in reply to: Lance127

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.
Message 19 of 40
Anonymous
in reply to: Anonymous

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

img.jpg

Message 20 of 40
Anonymous
in reply to: Anonymous

I don't be able to find the error.

 

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

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

Post to forums  

Autodesk Design & Make Report