I suppose you can only get the transformation of coordinate system in its context. You cannot get the transformation of the CS which is in the part from the top assembly.
How is one supposed to get a transform from a part's CS relative to the top level assembly's origin? I'm assuming I'm simply using the wrong function, but searching the help keeps leading me back to this one.
Surely you just need Component2::Transform2 ?
I had seen that, but I have an issue traversing the assembly to get the Component2 object.
swAsm->GetComponents(false, &vComps); // This returns an array of IDispatch, not IComponent2 as the help states
HRESULT CompArray = SafeArrayAccessData(vComps.parray, (void**)&D_vComps); // Access the data in the array
for (int i=0; (sizeof(D_vComps)/sizeof(D_vComps)); i++) // For each element in the array
HRESULT compOK = D_vComps[i].QueryInterface(IID_IComponent2, (void**)&swComp); // ACCESS VIOLATION HERE
I have used QueryInterface at a different location to get IModelDocExtension from IDispatch without issue, but I'm not sure why I receive an access violation here.
I tend not to use GetComponents. I use IGetChildren from IComponent2.
You use ActiveConfiguration on the IConfigurationManager of the top level assemly to get an IConfiguration.
Then call GetRootComponent3 to get an IComponent2.
Finally call IGetChildren on that.
Works every time for me.
This seems to be a much better route.. How do you set up the array of IComponent2's that IGetChildren returns? You run IGetChildrenCount to determine the size of the array, but what I have below throws the "no suitable conversion from std::vector to IComponent2 exists" error.
Without IGetChildrenCount and just doing the following returns a pointer to null:
Sorry - I don't know enough about C++ to answer that. I use c# or VB - for exactly this sort of reason! You can spend longer sorting these casting problems out than writing the rest of the code.
Anyway, I think you're on the right lines. Hopefully someone else can solve the last part of the puzzle.
Just for the sake of completion... GetChildren() returns an array of IDispatch objects.You can access the array data via a SafeArray. You then use QueryInterface() to (in my interpretation) tell the system that the IDispatch object that swc[i] points to is an IComponent2 object. After that you can use the typical commands to calculate the transformation matrix.
SAFEARRAY *psa = V_ARRAY(&swCompChildren);
HRESULT CompArray = SafeArrayAccessData(swCompChildren.parray, (void**)&swc);
for (int i=0; i<=ChildrenCount; i++)
HRESULT compOK = swc[i]->QueryInterface(IID_IComponent2, (void**)&swComponent);