Hi @c_bouw. When using the Event Triggers dialog to automate stuff, we have less control over the specifics than when we automate stuff using the object Events themselves, with our own custom event handling codes, but custom event handler codes are generally best suited for use in Inventor add-ins, not regular iLogic rules. When we open an assembly or drawing, that also opens all of the documents being referenced by the assembly or drawing, and when we save an assembly, it sometimes also saves some of its referenced documents at the same time. In situations like this, I almost always instruct folks to use the 'ThisDoc.Document' iLogic phrase in their iLogic rules to refer to the document that the rule is to focus on, instead of ThisApplication.ActiveDocument, because ThisApplication.ActiveDocument will always refer to whichever documents happens to be currently visible on your screen at the time, which causes a lot of folks, over lots of years, lots of troubles, like in this case. The 'ThisDoc' iLogic term is pretty dynamic, and refers to different documents in different situations, but there is next to no accurate official documentation explaining exactly how it will work in all those different situations, so I have had to conduct my own testing and research about its functionality over the years.
When used in an internal iLogic rule (the rule is saved within an Inventor document, not external), it will default to representing the document that the rule is saved within. If used in an external iLogic rule, then it will default to representing the document that was 'active' (visibly showing on your screen) when the rule was first started. If the rule was triggered to run by an Event Trigger, it will represent the document that the Event happened in. If the rule was ran by calling it to run from another rule, using something like 'iLogicVb.Automation.RunExternalRule(oDocForRuleToTarget, "ExternalRuleName")', then it will represent the document that oDocForRuleToTarget variable represents. And so on. If any of the rules involved in any of these situations used the phrase 'ThisApplication.ActiveDocumet' anywhere within their code, thinking that they are referring to the document that the rule is to take actions on, then they most likely will not work correctly, and those references will likely need to be changed to using 'ThisDoc.Document' to make them work right, if they may be called to run remotely by things like Event Triggers, or codes like RunRule, or other similar situations.
If you rule is for zooming and positioning a model on the screen, and it is possible that this document may not be the 'active' document, then you could use something like the following:
Dim oDoc As Document = ThisDoc.Document
If oDoc IsNot ThisApplication.ActiveDocument Then Return
If (Not TypeOf oDoc Is PartDocument) And (Not TypeOf oDoc Is AssemblyDocument) Then Return
'at this point, we know that this document is the 'active' one, and is a Part or Assembly
'now use the oDoc variable as your reference to this document, for any further code
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield

(Not an Autodesk Employee)