Can any iLogic rule run in the VBA editor of Inventor?

Can any iLogic rule run in the VBA editor of Inventor?

Anonymous
Not applicable
2,174 Views
19 Replies
Message 1 of 20

Can any iLogic rule run in the VBA editor of Inventor?

Anonymous
Not applicable

Hi,

my question is theoretical and generic, I do not want to solve any specific problem for now.

 

Question: can any valid iLogic rule be executed by the VBA editor of Inventor in the same way it can be executed by built-in iLogic editor, that is without any modifications in the original iLogic source code?

 

For valid iLogic rule I mean an iLogic rule with valid syntax for iLogic, that is: the iLogic rule can be executed without problems using the iLogic editor of Inventor.

 

The question is useful to me to understand if I can run all my iLogic rules by pasting the source code directly in VBA editor, because I find annoying two big limits with iLogic editor:

  1. I can't stop any iLogic rule during execution, if I decide to stop it.
  2. The iLogic editor, when opened, freezes Inventor completely, and I can't quickly change something in my 3D assembly without closing first the iLogic editor.

The VBA editor (that is a built-in tool of Inventor, like iLogic editor) allows both points 1 and 2 above.

 

I know I could try myself if some iLogic rules run without modifications inside VBA editor, but I prefer for now to ask you if iLogic is a subset of VBA (I do not think the opposite is true).

 

Thanks

Regards

 

0 Likes
2,175 Views
19 Replies
Replies (19)
Message 2 of 20

bradeneuropeArthur
Mentor
Mentor
You can run a ilogic code from Vba by referencing them...

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 20

Anonymous
Not applicable

Hi @bradeneuropeArthur, yes, but in this way can I stop iLogic rule, when running, with Ctrl+Break, like for VBA? 

0 Likes
Message 4 of 20

Anonymous
Not applicable

Only to add that I found a iLogic method/function "InventorVb.RunMacro()" that runs a VBA macro using the comfortable iLogic browser (that in my case is under the Model browser with all parts and sub-assemblies).

 

In other words, I have an external iLogic rule named "RUN iLogic-RuleName.vb" with following valid iLogic syntax:

InventorVb.RunMacro("DocumentProject", "ThisDocument", "Main")

and a VBA macro/code (a simple test code) saved inside VBA editor in "DocumentProject" -> "ThisDocument" and the code is:

Sub Main()
    Dim i As Integer
    For i = 1 To 10
        MsgBox ("Test" + Str(i))
    Next
    Call finish()
End Sub

Sub finish() MsgBox ("Finish.") End Sub

Well, when I run the iLogic rule "RUN iLogic-RuleName.vb" from iLogic browser, Inventor runs the above VBA code in "ThisDocument" as I expect, and I can stop execution with classic Ctrl+Break, without opening the VBA editor.

 

Now I repeat the question: can any valid iLogic rule (any) run using VBA editor?

If yes, I'd like to know if can iLogic provide a command/function able to not only run a VBA macro, but also copy the content of a file (with any valid iLogic rule), paste the content in VBA editor in "ThisDocument" and execute the copied code as if it were a classic iLogic rule.

 

Thanks 

 

0 Likes
Message 5 of 20

pball
Mentor
Mentor

I'm going to say no you cannot take any iLogic code and run it without edits in the VBA editor. iLogic has shortcuts and supported features that VBA does not. VBA does not support try/catch and you can't set a variable equal to something on the same line you Dim it. There are other differences also.

 

Though if you format and use features that are common to both iLogic and VBA then you could create code that is portable between the two.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Message 6 of 20

Anonymous
Not applicable

Hi @pball, what you said is interesting and nice:


@pball wrote:

Though if you format and use features that are common to both iLogic and VBA then you could create code that is portable between the two.


I'm sorry with you all if this post is not related to a real/practical Inventor problem, but it is related to some curiosities that I have in mind about programming tools of Inventor.

 

I thought iLogic was a subset of VBA, but now I understand that iLogic and VBA are two quite different built-in programming tools of Inventor.

 

So synthesizing, by reading something more in the forum (thank you all users that share info about this topic, and please, if you can, kindly confirm the following):

  1. Built-in available IDEs for automatic tasks in Inventor:
    1. iLogic: based on language VB.NET (powerful language), but in my opinion the built-in editor that comes with Inventor is not the best tool for test/debugging own codes.
    2. VBA: based on a restricted VB set of commands/methods, but it comes with a better IDE that allows user to debug own code and to operate with Inventor with the IDE opened, for quickly changes of 3D parts if needed.
  2. VB.NET is available only if user downloads it from a Microsoft link (that is: it is not a built-in tool that comes with Inventor).
  3. I understand that with some skills on both iLogic (VB.NET) and VBA languages (and Inventor API of course), user could create always a rule with valid syntax for both languages taht perform any useful automatic task (for example to create PDF of all drawings inside a folder).

 

Well, for now I decided to study deeper VBA tool instead of iLogic, because I don't want to install a new software in my PC like IDE for VB.NET (and I find built-in iLogic editor too little comfortable for beginners). I find built-in VBA for Inventor good enough for my purposes.

 

While I wait for a next Inventor version or update with a more advanced iLogic editor that allows user to interact with Inventor without closing the code editor and also allows user to stop execution of code with a simple shortcut key, I'm trying to understand, as a workaround, if some iLogic commands exist able to interact with the VBA editor/tool of Inventor.

 

An example: suppose I have two external iLogic rules named "EDIT rule_1.vb" and "RUN rule_1.vb"  and a VBA code saved in an external file and named "rule_1.vb" (the three files are in the same folder and the two iLogic rules are External rules and visible in iLogic browser, so correctly imported in the iLogic browser).

The VBA code "rule_1.vb" could be (it is a test example, it is the example of my previous post):

Sub Main()
    Dim i As Integer
    For i = 1 To 10
        MsgBox ("Test" + Str(i))
    Next
    Call finish()
End Sub

Sub finish()
	MsgBox ("Finish.")
End Sub

Well

  • I'd like to run iLogic rule "EDIT rule_1.vb" so that it opens the external file "rule_1.vb", copies the content in clipboard, opens the VBA editor, paste the content in VBA editor inside a blank/empty "ThisDocument" window of the active part or assembly (see image below) and finally puts the cursor at the beginning of the code pasted, that is before "Sub Main()" of code above (the VBA code).
  • About iLogic rule "RUN rule_1.vb", if run, I'd like it opens the external file "rule_1.vb", copies the content in clipboard,  paste the content in VBA editor inside a blank/empty "ThisDocument" window of the active part or assembly (without opening the VBA editor) and finally runs it.

VBA editor.png

 

Can you help me about iLogic (VB.NET) commands/methods/functions able to interact with VBA tool of Inventor for the purposes I have described?

 

Thanks

Regards

0 Likes
Message 7 of 20

Anonymous
Not applicable

Hi, I found this link useful for my task, but it works with VBA for MS Excel. Do you know if VBA for Inventor has a "Trust access to the VBA project object model" option, like for MS Excel 2010 I use (see image below)?

 

For MS Office 2010, in order to enable this option, you must go to: File->Option->Trust Center->Trust Center Settings...->Macro Settings. I don't know how to enable it in Inventor VBA.

 

This option, if enabled, allows to create VBA programs that add/delete other VBA programs programmatically, and this comes close to what I want to do using comfortable iLogic browser.

 

access VBA proj.png

 

Thanks

 

0 Likes
Message 8 of 20

Anonymous
Not applicable

Really nobody here with skills in VBA or iLogic can answer?

 

Sorry but I'm interested about it and I do not want to wait a long time to have an answer, I just need an answer like "yes, you can enable the option Trust access to the VBA project object model for Inventor VBA" or "you can not enable the option because this option is available only with Microsoft Office products".

 

Thank you

0 Likes
Message 9 of 20

bradeneuropeArthur
Mentor
Mentor

You can run a ilogic code from Vba by referencing them...

 

and no you can't "Trust access to the VBA project object model for Inventor VBA"  via programming, because of security reasons...

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 10 of 20

Anonymous
Not applicable

Hi @bradeneuropeArthur, thank you, I don't want to enable that option programmatically, but manually only one time for my computer, so, after that, I can interact with VBA editor every time I want following the instructions here.

 

Also for MS Office user can't enable programmatically that option, only manually, and it is ok. But while I know how to enable it manually in MS Office, I don't know how to enable it manually for Inventor. Any VBA options in some hidden submenus? I mean a submenu of Inventor like the one I showed in image of my previuos post (valid for MS Office 2010, but it is available also for MS Office 2003).

 

And about reference VBA with iLogic, what dou you mean? I need to find a working solution in order to use VBA editor as main editor for my rules development that I decided to write in VBA language instead of iLogic language, and I want to use some iLogic rules written in iLogic language (and available in the comfortable iLogic browser) to execute some external VBA macros for: opening VBA editor programmatically, paste some VBA code inside VBA editor, execute the VBA code pasted, etc...

 

This because i prefer VBA editor instead of iLogic editor to write my rules (as I'm not an expert in programming, I prefer a way to stop my rules with keypress if my loop is bad, with iLogic it is impossibile and this is bad for debugging own rules).

 

Thanks

Regards

0 Likes
Message 11 of 20

bradeneuropeArthur
Mentor
Mentor

for inventor there is no option needed to allow maco's to run.

you can load straight VBA code in I-logic.

You can also run I-logic code with VBA.

 

 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 12 of 20

Anonymous
Not applicable

Ok, so no option "Trust access to the VBA project object model" or similar for Inventor VBA to be enabled manually in order to use Inventor VBA editor to program the editor itself. I'm disappointed about it.

 

About what you said "you can load straight VBA code in I-logic.", I think an example is what I wrote in message #4, that is: by running the ilogic rule with function "InventorVb.RunMacro()" I can execute an external VBA macro and I can stop its execution with Ctrl+Break.

 

About what you said "You can also run I-logic code with VBA." can you kindly suggest me a little working example?

 

Thank you so much

Regards

0 Likes
Message 13 of 20

bradeneuropeArthur
Mentor
Mentor
Public Sub LaunchMyRule()

  RuniLogic "Rule9" 'the name of the rule

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.RunRule oDoc, RuleName '<- name of the rule again, changed RunExternalRule to RunRule here
End Sub

Function GetiLogicAddin(oApplication As Inventor.Application) As Object
'Find the add-in you are looking for
Dim addIn As ApplicationAddIn
'Set addIns = oApplication.ApplicationAddIns '<- errors out on this part


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

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

Message 14 of 20

Anonymous
Not applicable

Hi @bradeneuropeArthur, thanks, I'm trying your code with my rules and I will perform some tests. Thanks for sharing it.

 

I'm also trying this other VBA code (named "TEST1" for example) that I put inside "ThisDocument" of VBA editor of the opened Inventor part/assembly I'm working on:

 

Sub Main()
        Dim VBProj As VBIDE.VBProject
        Dim VBComp As VBIDE.VBComponent
        Dim CodeMod As VBIDE.CodeModule
        Dim LineNum As Long
        Const DQUOTE = """" ' one " character

        Set VBProj = ActiveDocument.VBProject
        Set VBComp = VBProj.VBComponents("ThisDocument")
        Set CodeMod = VBComp.CodeModule
        
        With CodeMod
            LineNum = .CountOfLines + 1
            .InsertLines LineNum, "Public Sub SayHello()"
            LineNum = LineNum + 1
            .InsertLines LineNum, "    MsgBox " & DQUOTE & "Hello World" & DQUOTE
            LineNum = LineNum + 1
            .InsertLines LineNum, "End Sub"
        End With
End Sub

In MS Office Word and Excel the code "TEST1" works and below the Main code, after run it, a new code is added:

Public Sub SayHello()
    MsgBox "Hello World"
End Sub

The problem is that I can't run the code "TEST1" in VBA editor of Inventor, the error message is: "Run-time error '424': Object required".

 

Can you kindly tell me if the code "TEST1" can be modified in order to work with Inventor VBA editor?

 

Many thanks,

Regards

 

 

 

0 Likes
Message 15 of 20

bradeneuropeArthur
Mentor
Mentor

is this an external rule?

 

iLogicAuto.RunRule oDoc, RuleName '<- name of the rule again, changed RunExternalRule to RunRule 

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 16 of 20

Anonymous
Not applicable

No, it is a VBA code, not an iLogic code, and I'm trying to run it using VBA editor of Inventor. But it fails. It is not related to you code in message #13. Can you help me about it?

 

And, about your code in message #13, how can I modify it for external iLogic rule usage? For example my iLogic rule is named "test1.vb" andI see it in my iLogic browser (in External rules).

 

Thank you!

0 Likes
Message 17 of 20

bradeneuropeArthur
Mentor
Mentor

What code are you try to run exactly?

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 18 of 20

Anonymous
Not applicable

Sorry @bradeneuropeArthur, ok I explain it better.

 

I want to perform two tests with VBA for Inventor to learn something new about it.

 

  • The first test is the execution of you VBA code at message #13 with an external iLogic rule I have in my iLogic Browser. The external iLogic rule is:
Sub Main()
    Dim i As Integer
    For i = 1 To 10
        MsgBox ("Test" + Str(i))
    Next
    Call finish()
End Sub

Sub finish()
	MsgBox ("Finish.")
End Sub

and its name is "Rule1.vb". How can I run your code to execute the iLogic rule "Rule1.vb" with the VBA editor of Inventor, that is without running it with iLogic Browser?

 

  • The second test I want to perform is the execution of the following VBA code (named "TEST1") in VBA editor of Inventor, in order to create programmatically a new macro below TEST1 (TEST1 is the main vba macro inside "ThisDocument" of vba editor):
Sub Main()
        Dim VBProj As VBIDE.VBProject
        Dim VBComp As VBIDE.VBComponent
        Dim CodeMod As VBIDE.CodeModule
        Dim LineNum As Long
        Const DQUOTE = """" ' one " character

        Set VBProj = ActiveDocument.VBProject
        Set VBComp = VBProj.VBComponents("ThisDocument")
        Set CodeMod = VBComp.CodeModule
        
        With CodeMod
            LineNum = .CountOfLines + 1
            .InsertLines LineNum, "Public Sub SayHello()"
            LineNum = LineNum + 1
            .InsertLines LineNum, "    MsgBox " & DQUOTE & "Hello World" & DQUOTE
            LineNum = LineNum + 1
            .InsertLines LineNum, "End Sub"
        End With
End Sub

The vba macro "TEST1" fails and gives error "Run-time error '424': Object required". Why?

 

Hope it is more clear.

Thank you

Regards

 

0 Likes
Message 19 of 20

Anonymous
Not applicable

Hi @bradeneuropeArthur, I've found the solution for the first test in this forum, this is the link.

Now, thanks to your help and that link, I can run any external iLogic rule by using VBA editor. Unfortunately I noticed that, even in this way, I can't stop execution of iLogic rule with Ctrl+Break (since I'm in the VBA editor),  because the iLogic rule is executed as an independent code that is not a subprocess of the VBA code.

 

Anyway the working VBA code I use to run external iLogic rules is (the external iLogic rule is named "test.vb" and it needs to be visible in iLogic browser of Inventor):

 

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



Public Sub RuniExtLogic(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
	On Error GoTo errorline
  iLogicAuto.RunExternalRule oDoc, RuleName
  Exit Sub
errorline:
    MsgBox "Missing External rule: " & RuleName
End Sub



Sub main()
	Call RuniExtLogic("test")
End Sub

 

I have a last problem for now: how to run the VBA code of my second test, can someone expert in VBA kindly show me why I can't run this code? The problematic code is the second one of message #18.

 

Thanks all,

Regards

0 Likes
Message 20 of 20

Anonymous
Not applicable

Hi, I want to share a solution for my question about programming the VBA editor of Inventor.

 

In summary, I wanted a VBA code to run only one time and able to create programmatically several VBA subroutines inside a module (TempModule for example) of the opened/active Inventor object (ipt, iam, idw, ...). In this way I can execute an external rule that executes a specific VBA subroutine inside TempModule and I can stop it with the common Ctrl+Break (only valid for VBA and not for iLogic).

 

The solution I found is inspired by an answer provided by @bradeneuropeArthur that can be found here. Thanks @bradeneuropeArthur!

 

Procedure tested on Inventor 2018 Pro (if you are interested ;-)):

 

1) Copy inside Default.ivb of Inventor the following code:

Sub AutoMacroAdd()

    '' This to enable SendKeys Alt+F11 in order to open VBA editor (without it we obtain an error at "Set VBProj = ..."):
    Dim dTILL As Double
    SendKeys ("%{F11}"), True
    dTILL = Now + TimeSerial(0, 0, 1)
    Do While dTILL > Now: DoEvents: Loop

    Dim VBProj As VBIDE.VBProject
    Dim VBComp As VBIDE.VBComponent
    Dim CodeMod As VBIDE.CodeModule
    
    Set VBProj = ThisApplication.ActiveDocument.VBAProject.VBProject

    On Error Resume Next
    Dim Element As Object

    For Each Element In VBProj.VBComponents
        VBProj.VBComponents.Remove Element
    Next

    Set VBComp = VBProj.VBComponents.Add(vbext_ct_StdModule)
    VBComp.Name = "TempModule"

    Set CodeMod = VBComp.CodeModule

    Dim strFilename As String: strFilename = "C:\VBA - Test_for_iLogic_Browser.vb"
    Dim strFileContent As String
    Dim iFile As Integer: iFile = FreeFile

    Open strFilename For Input As #iFile
        strFileContent = Input(LOF(iFile), iFile)
    Close #iFile

    With CodeMod
        LineNum = .CountOfLines + 1
        .InsertLines LineNum, strFileContent
    End With
    
    '' This to close VBA editor:
    SendKeys ("%{F4}")
    
End Sub

2) Enable option "Microsoft Visual Basic for Applications Extensibility 5.3" in VBA editor (Tools, References..., ), save Default.ivb by closing Inventor and reopening it

3) Create the VBA macro "VBA - Test_for_iLogic_Browser.vb" in C: for the test, with the following code:

Sub Test_for_iLogic_Browser()
    Dim i As Integer
    For i = 1 To 4
        MsgBox ("Test" + Str(i))
    Next
    Call finish()
End Sub

Sub finish()
	MsgBox ("Finish.")
End Sub

4) Create two external iLogic rules (in iLogic language) in the path you want and with the following content:

for iLogic rule named "Initialize VBA Modules.vb":

InventorVb.RunMacro("ApplicationProject", "Module1", "AutoMacroAdd")

for iLogic rule named "Run VBA - Test_for_iLogic_Browser.vb":

InventorVb.RunMacro("DocumentProject", "TempModule", "Test_for_iLogic_Browser")

5) Now create a new Inventor file (ipt, iam, etc..) and execute the external rule "Initialize VBA Modules" in your iLogic browser: it should create programmatically in the VBA editor the code "VBA - Test_for_iLogic_Browser.vb" in a module named "TempModule".

6) Now execute the external rule "Run VBA - Test_for_iLogic_Browser" in your iLogic browser: it should execute the VBA subroutine "Test_for_iLogic_Browser" that you can interrupt it with Ctrl+Break (very useful when developing a new code).

 

The only required iLogic codes are the ones you need to execute VBA macros.

The main external rules executed for Inventor purposes (renaming iProperties of all files, hiding of all parts inside a close path, etc...) must be in VBA language, because only with it you can stop execution.

 

Reasons: I find iLogic browser more comfortable than the VBA code selector (when opened it freezes entire Inventor application, like the iLogic editor) but I prefer VBA environment and editor than iLogic one because user can modify VBA code on the fly without closing the editor and you can stop execution of all codes (impossible with iLogic).

 

I will try to improve the code by changing the code line "Dim strFilename As String: strFilename = "C:\VBA - Test_for_iLogic_Browser.vb"" in order to have a Default.ivb file independet from specific VBA codes.

 

Hope the procedure I share helps someone like me about programming.

Regards

 

 

0 Likes