solidworks二次开发之遍历装配体

 HRESULT retval;

 CString myString;


 CComPtrpModel;
 retval = m_iSldWorks->get_IActiveDoc2(&pModel);
 if(pModel == NULL)
 {
  AfxMessageBox(_T( "获取活动文档失败"));
  return ;
 }

 CComBSTR title;
 pModel->GetTitle(&title);

 CString temp(title);

 myString=myString+temp+"/r/n";
 

 CComPtrpConfig;

 pModel->IGetActiveConfiguration(&pConfig);

 ASSERT(pConfig);

 CComPtrpRoofComp;
 pConfig->IGetRootComponent(&pRoofComp);


 int componentCout;
 pRoofComp->IGetChildrenCount(&componentCout);

 VARIANT vChildComp;
 pRoofComp->GetChildren(&vChildComp);
 
 SAFEARRAY *safeComp;
 safeComp=V_ARRAY(&vChildComp);
 
 LPDISPATCH *safeArraycomp;
 SafeArrayAccessData(safeComp,(void **)&safeArraycomp);

 for (int i=0;i {
  CComQIPtrpChildComp;
  pChildComp=safeArraycomp[i];


  CComBSTR comName;
  pChildComp->get_Name(&comName);

  CString childTemp (comName);
  myString=myString+childTemp+"/r/n";
  
 }

 

 AfxMessageBox(myString);

 

你可能感兴趣的:(solidworks二次开发之遍历装配体)