I'm trying to obtain the name of each component in an assembly file using an out-of-process C++ code. I have the assembly pointer IAssemblyDoc, and figured that the best way to do this would be to use the GetComponents member of this pointer. But I'm having difficulty figuring out how to convert my VARIANT return value into an array of component pointers, each of which would store the name for the given component. Here is my code so far:
CComPtr
CComPtr
CComPtr
HRESULT hres = NOERROR;
int i;
long fileError, fileWarning, num_com;
CoInitialize(NULL);
hres = swApp.CoCreateInstance(__uuidof(SldWorks), NULL, CLSCTX_LOCAL_SERVER);
hres = swApp->put_UserControl(VARIANT_TRUE);
hres = swApp->put_Visible(VARIANT_FALSE);
TCHAR szFileName[255];
_tcscpy(szFileName, _T("C:\\Temp\\ujoint.sldasm"));
_bstr_t sPartName(szFileName);
CComBSTR bsPartName;
bsPartName.AppendBSTR(sPartName);
CComBSTR sDefaultConfiguration(L"Default");
hres = swApp->OpenDoc6(bsPartName, swDocASSEMBLY, swOpenDocOptions_Silent, sDefaultConfiguration, &fileError, &fileWarning, &swModel);
hres = swModel->QueryInterface(IID_IAssemblyDoc, (void**)&swAssembly);
if (hres == S_OK && swAssembly)
{
VARIANT swComponentArray;
hres = swAssembly->GetComponentCount(VARIANT_TRUE, &num_com);
hres = swAssembly->GetComponents(VARIANT_TRUE, &swComponentArray);
but I'm at a loss at how to proceed. My goal is to obtain an array of pointers to IComponents2, so that I can use the member get_Name2 to obtain the name of each component in the assembly. Thank you!
SolidworksApi macros