SubOccurrences triggers OnOpenDocument event on referenced assembly children
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm a long time Inventor api user and I just discovered this behaviour that looks strange to me.
1. Open Inventor
2. Open Event Watcher in C:\Users\Public\Documents\Autodesk\Inventor 20XX\SDK\DeveloperTools\Tools\EventWatcher\bin\Release and check ApplicationEvents.OnOpenDocument event listener.
3. Open a drawing referencing an assembly with 2 parts.
4. Now, Inventor tells me there are 4 documents opened with unique file names (idw, iam and the 2 parts).
5. On the other hand looking at the event watcher I see it has been triggered just two OnOpenDocument events on idw and iam. Why?
Going deeper if I add the following iLogic rule to count all occurrences recursively I'll see the line suboccs = subocc.SubOccurrences triggering the 2 remaning OnOpenDocument events.
Is this an optimization done in recent versions?
The problem is that in drawing referencing large assembly this counting process takes a long time due to documents opening.
Sub Main() Dim drwDoc As DrawingDocument = ThisApplication.ActiveDocument Dim asmDoc As AssemblyDocument = drwDoc.ReferencedDocuments.Item(1) Dim count = 0 CountSubOccs(asmDoc.ComponentDefinition.Occurrences, count) MsgBox(count) End Sub Sub CountSubOccs(ByVal occs As ComponentOccurrences, ByRef counter As Long) For Each subocc As ComponentOccurrence In occs Try If subocc.IsSubstituteOccurrence Then Continue For Catch End Try counter += 1 Dim suboccs = Nothing Try suboccs = subocc.SubOccurrences Catch Continue For End Try CountSubOccs(suboccs, counter) Next End Sub