Hi @br.sbrava. I can not remember the actual date that Autodesk took down everyone's 'Contribution Articles' which were posted in the Autodesk knowledge base area, but it has been a few years now, and when they did, it left a TON of broken Links all over the Autodesk Community afterwards, which really disappointed a lot of folks. I think I had around 16 of them at the time, but I only 'preserved' the contents of a few of the most popular ones at that time, by copying most of their contents over into Microsoft Word documents, then exporting those to PDFs. I am not sure I still have that specific article, but I will attach a few similar resources I have on hand which I think you will find helpful.
I can summarize that article from memory though:
The 'ThisApplication.ActiveDocument' property (defined within Inventor's API directly, not in iLogic) will always return Inventor's true 'active' Document, no matter what else is going on. Inventor's active document is the one visibly showing on your screen, ready for editing, at the moment that property's value is used. Often times this means that if you start (run) an iLogic rule while an assembly is Inventor's active document, it will usually remain Inventor's active document even if your rule is accessing many other 'referenced' or invisibly opened documents in the background. This usually means you would have to use other ways to access those other documents that you want the rule to interact with besides that code phrase. However, our code process can visibly open other documents, then 'activate' them, if necessary, which may make them the new active document, depending on the situation. So, this is the easiest one to explain.
'ThisDoc' is an iLogic 'Rule Object' (predefined/set rule variable) representing the ICadDoc Interface, which is unique to the iLogic add-in's API (not in Inventor's API). This Interface has several Properties & Methods, but we will focus on its ICadDoc.Document Property here. Using this property is the most popular, and most robust (and often most accurate) way to access the 'current' (not necessarily 'active') Document that we want our iLogic rule to be working with. This is because it works differently in different situations, which makes its 'official' documentation so lacking, and in need of much further explanation. Its official documentation only says "Gets the document in which the rule is running."
- When using an 'internal' (saved within the Inventor Document) iLogic rule: 'ThisDoc.Document' will point to the Document which the current iLogic rule is saved within - by default, with some possible exceptions
- When using an 'external' iLogic rule: 'ThisDoc.Document' will point to the Document that was 'active' when that rule first started - by default, with some possible exceptions
- When an iLogic rule was 'triggered' to run by a setting in the iLogic Event Triggers dialog: 'ThisDoc.Document' will point to the Document that the Event was triggered within
- When we use the iLogic methods like RunRule, RunRuleWithArguments, RunExternalRule, RunExternalRuleWithArguments to run a secondary rule from within a primary rule, which are listed under the IiLogicAutomation Interface (accessed by 'iLogicVb.Automation' code phrase), those methods ask us to input the Document that we want the 'other' rule (which we are about to run) to focus its attention on. In those types of cases, when the 'ThisDoc.Document' phrase is used in that other rule, it will point to that specified document that we input in those methods.
- There are likely other similar scenarios which could be mentioned here, too.
In many of those cases, the value of the 'ThisDoc.Document' property can potentially be a different Document than the one we get from the 'ThisApplication.ActiveDocument' property. On the other hand, when we are writing code to automate Inventor in Inventor's VBA editor, or when we are writing code for an Inventor add-in (ApplicationAddIn), of for an external EXE type application, the 'ThisDoc' term is not recognized, because it is unique to the iLogic add-in, which is why the 'ThisApplication.ActiveDocument' remains popular in code examples. One of the most common scenarios where this mis-match happens is when editing or saving a Drawing or an Assembly, because both of those document types 'reference' other documents in the background. When we open a drawing or assembly, Inventor also partially or fully loads all of those referenced documents into Inventor's session memory invisibly, in the background. And if any (savable) changes are made to any of those referenced documents while the parent assembly or drawing is open, and you attempt to save the assembly or drawing, it will also want to save the referenced documents that were changed at that time. When those changes or saves happen to those background referenced documents, it sometimes 'triggers' those Event Triggers settings to run iLogic rules on those background documents...none of which are Inventor's true 'active' document at that moment in time. So, if the code phrase 'ThisApplication.ActiveDocument' is being used within those 'triggered' rules to refer to the document that those rules should be working on, there is a good chance that they will be attempting to access the wrong document, which will often cause unexpected errors...or worse yet, unexpected changes to the wrong document(s). Other than the Inventor.Application object itself, which the 'ThisApplication' term represents, the Document object is the next most important object that our iLogic rules reference/use/access, so it is important to understand how to access the right ones, the right way. Whew. 😅
Wesley Crihfield

(Not an Autodesk Employee)