Hallo,
ich versuche in C++ mit COM auf die Komponenten einer Baugruppe
zuzugreifen. Die verfügbaren Beispeile sind in SWX
< 2006 so, dass
IComponent2::IGetChildren ein Array zurückliefert. In 2006 wird ein
ptr auf ein IComponent2 zurückgegeben. Wie soll ich über die
Komponenten iterieren. Konventionelles Iterieren wie über C-Ptr
scheint nicht zu funktionieren.
Code:
#include <atlcomcli.h>
#include <mmc.h>
#include <comdef.h>
#import "D:\Programme\SolidWorks\sldworks.tlb"
#import "D:\Programme\SolidWorks\swconst.tlb"
//#include "swconst.tlh"
//#include "sldworks.tlh"
//#include "sldworks.tlh"
int
main(int argc, const char* argv[])
{
HRESULT result = CoInitialize(NULL);
CLSID clsid;
result = CLSIDFromProgID(OLESTR("SldWorks.Application"), &clsid);
CComPtr <IUnknown> unknown;
result = GetActiveObject(clsid, NULL, &unknown);
CComQIPtr <SldWorks::ISldWorks> sldworks;
result = unknown->QueryInterface(__uuidof(SldWorks::ISldWorks), (LPVOID*)&sldworks);
result = sldworks->SetUserPreferenceToggle(SwConst::swExtRefUpdateCompNames, FALSE);
SldWorks::IModelDoc2Ptr document = sldworks->GetActiveDoc();
CComQIPtr <SldWorks::IConfigurationManager> cfgmgr;
result = document->get_ConfigurationManager(&cfgmgr);
CComQIPtr <SldWorks::IConfiguration> activeconfig;
result = cfgmgr->get_ActiveConfiguration(&activeconfig);
CComQIPtr <SldWorks::IComponent2> root_component;
root_component = activeconfig->IGetRootComponent2();
int children_count = root_component->IGetChildrenCount();
CComQIPtr <IComponent2> children;
children = root_component->IGetChildren();
return 0;
}
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP