I don't really have much time right now to jump back into this, but I still think the main detail causing problems here is the 'context' related to 'proxy levels'.
- When there are more than 2 levels (steps in assembly structure) in a 'main' (highest level) assembly...
- The 'NativeObject' of a proxy can actually be another proxy.
- A proxy is not always in the 'context' of the 'main' (highest level) assembly.
- If you access the 'definition' (ComponentDefinition) of a proxy, then you are accessing the 'context' where the true 'original' was created.
- But once in the definition of a proxy, you then have to find the source object again, in that context.
I believe we can actually 'recurse' the levels (or contexts) of proxies, in either direction.
As an example, lets look at the 'Face' of a part ("Part 1.ipt"). An occurrence of that part is placed into an assembly, making the default name of that occurrence "Part 1:1", then that assembly is saved as "Asm 1.iam". Then an occurrence of that assembly is placed into a second assembly, where that occurrence of the assembly gets named "Asm1:1", then that second assembly gets saved as "Asm 2.iam". At this point, 'Asm 1' is a sub assembly within 'Asm 2'. Then we have the following structure.
- Asm 2 (contains occurrence named "Asm 1:1")
- Asm 1 (contains occurrence named "Part 1:1")
- Part 1 (contains original Face object 'Face 1")
- Face 1 (just a Face, within that part)
(It gets even more confusing when there are 'parallel' occurrences/instances of the same part at multiple levels of the assembly, but I won't go there right now, to keep the 'concept' simple.)
In the scenario where I want to get and use that face of that part in the context of the main assembly (which will be a FaceProxy object), I usually have to start from the bottom (lowest level), then work my way back up. In that process, I start with the true original Face object that is in the context/definition of the part, and the lowest level component occurrence (ComponentOccurrence object) of that part, which is in the context of the assembly named 'Asm 1'. At that point, I use that component occurrence's ComponentOccurrence.CreateGeometryProxy method, to get the first proxy of that part's face, which will be in same context as the component occurrence (in the context of 'Asm 1'). But we are not done yet, because that proxy is not in the context of 'Asm 2', where we need it. So next, I need to do that last step another time, but this time we will be using the method from the component occurrence object representing the sub assembly named 'Asm 1', and the proxy we got from the first step. In this step we will be getting a proxy of a proxy, instead of a proxy of an original. The proxy we get from that second step will finally be in the 'context' of 'Asm 2'. We can then use that final resulting proxy for measurements &/or constraints directly in the context of the assembly named 'Asm 2'.
Similarly, going the other direction, if we are starting from the context of 'Asm 2', and want to access the 'true original' 'Face 1' in that part (not just a proxy of it), we select the 'proxy' of it in the context of 'Asm 2' first. Then we use that proxy's 'NativeObject' property to get a reference to the 'proxy' that is in the context of 'Asm 1'. Then we use the 'NativeObject' property of that resulting proxy to get to the 'true original' in the part.
There are two levels of proxies in that process, in either direction, not just one. That concept of there possibly being multiple 'levels' of proxies, with each being in a different 'context', trips up most folks, and can be difficult to picture in our heads. Especially when the proxy is a ComponentOccurrenceProxy, instead of just the proxy of a face or edge.
I always seem to end up trying to explain too much when I start typing about something interesting. 😄
Wesley Crihfield

(Not an Autodesk Employee)