Solidworks 二次开发之遍历零件

 HRESULT retval;
 CComPtrpModel;
 retval = m_iSldWorks->get_IActiveDoc2(&pModel);
 if(pModel == NULL)
 {
  AfxMessageBox(_T( "获取活动文档失败"));
  return ;
 }
 CComPtrpPart;
 pModel->QueryInterface(IID_IPartDoc,(LPVOID *)&pPart);

 CComPtrpFeature;
 pPart->IFirstFeature(&pFeature);
 while (pFeature!=NULL)
 {
  
  
  
  CComPtrpSubFeature;
  pFeature->IGetFirstSubFeature(&pSubFeature);
  
  while(pSubFeature!=NULL)
  {
   CComBSTR bFeatureType;
   pSubFeature->GetTypeName(&bFeatureType);
   
   CString featureType (bFeatureType);
   
   if (featureType=="ProfileFeature")
   {
    CComPtrpDisp;
    pSubFeature->GetSpecificFeature2(&pDisp);
    
    CComPtrpSketch;
    pDisp->QueryInterface(IID_ISketch,(LPVOID *)&pSketch);
    
    if (pSketch!=NULL)
    {
     CComBSTR bSubFeatureName;
     pSubFeature->get_Name(&bSubFeatureName);
     
     CString subFeatureName(bSubFeatureName);
     AfxMessageBox(subFeatureName);
     
    }
    pSketch.Release();
   }
   CComBSTR bSubFeatName;
   pSubFeature->get_Name(&bSubFeatName);

   CString subFeatName (bSubFeatName);
   AfxMessageBox(subFeatName);

   CComPtrpNextSubFeat;
   pFeature->IGetNextSubFeature(&pNextSubFeat);
   pSubFeature=pNextSubFeat;
   
  }
  CComBSTR featureName;
  pFeature->get_Name(&featureName);
  
  CString message(featureName);
  
  TRACE1("%s",message);
  AfxMessageBox(message);

  CComPtrpNextFeat;
  pFeature->IGetNextFeature(&pNextFeat);
  pFeature=pNextFeat;
 }
 

你可能感兴趣的:(Solidworks 二次开发之遍历零件)