Hide Table of Contents

Enumerate Bodies Example (C++ COM)

This example shows how to use IEnumBodies to traverse the list of body objects. The IBody objects returned in IEnumBodies are the bodies associated with reference surfaces. This list does not include the part body itself. IEnumBodies::Next allows your application to get each individual body and then call appropriate methods for that body.

SolidWorks represents each reference surface with two IBody objects, one for the front face and one for the back face. The faces for each body pair should have Normal vectors that are opposite.


// Precompiled header

#include "stdafx.h"


#include <../appcomm/amapp.h>

#include "userapp.h"


void WalkGTBody()





 hres = UserApp->getSWApp()->get_IActiveDoc( &m_ModelDoc );  // Retrieve IModelDoc pointer

 if( m_ModelDoc == NULL )




 hres = m_ModelDoc->QueryInterface( IID_IPartDoc, (LPVOID *)&m_PartDoc);




 m_ModelDoc ->Release();




void walkBody(LPPARTDOC pPartDoc)



 HRESULT resultVal = pPartDoc->EnumRelatedBodies(&pBodyEnum);

 LPBODY pOldBody;

 resultVal = pBodyEnum->Next(1, &pOldBody, NULL); // Two bodies for each RefSurface

 while (S_OK == resultVal)



  resultVal = pOldBody->EnumFaces(&pFaceEnum);

  int faceNum = 0;

  LPFACE pFace;

  resultVal = pFaceEnum->Next(1, &pFace, NULL);

  while (S_OK == resultVal)


   VARIANT normal;



   LPBODY pCheckBody;

   resultVal = pFace->IGetBody(&pCheckBody);

   if (pCheckBody != NULL) pCheckBody->Release();



   pFace = NULL;

   resultVal = pFaceEnum->Next(1, &pFace, NULL);



  if (pFaceEnum != NULL) pFaceEnum->Release();


  pOldBody ->Release();

  pOldBody = NULL;

  resultVal = pBodyEnum->Next(1, &pOldBody, NULL);



 if (pBodyEnum != NULL) pBodyEnum->Release();




Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Enumerate Bodies Example (C++ COM)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2014 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.