Solidworks 二次开发之遍历零件

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/luzhengjun/article/details/3413214

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

 CComPtr<IFeature>pFeature;
 pPart->IFirstFeature(&pFeature);
 while (pFeature!=NULL)
 {
  
  
  
  CComPtr<IFeature>pSubFeature;
  pFeature->IGetFirstSubFeature(&pSubFeature);
  
  while(pSubFeature!=NULL)
  {
   CComBSTR bFeatureType;
   pSubFeature->GetTypeName(&bFeatureType);
   
   CString featureType (bFeatureType);
   
   if (featureType=="ProfileFeature")
   {
    CComPtr<IDispatch>pDisp;
    pSubFeature->GetSpecificFeature2(&pDisp);
    
    CComPtr<ISketch>pSketch;
    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);

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

  CComPtr<IFeature>pNextFeat;
  pFeature->IGetNextFeature(&pNextFeat);
  pFeature=pNextFeat;
 }
 

展开阅读全文

没有更多推荐了,返回首页