Hide Table of Contents

Get Circular Holes In Face Example (C++ COM)

This example shows how to calculate the number of circular holes in a selected face.  IEdge::IGetCurveParams2 and ILoop::IGetEdges return arrays, so this code must be used in an in-process DLL. Otherwise, use the methods IEdge::GetCurveParams2 and IEdge::GetEdges that return VARIANTs.

 

void GetCountHole1(LPMODELDOC2 pModelDoc, CString* Message)

{

 long lres=0;

 int pCount=0;

 LPSELECTIONMGR pSelectMgr=NULL;

 HRESULT hres=NULL;

 LPUNKNOWN pUnk=NULL;

 LPFACE SelectedFace=NULL;

 LPLOOP pLoop=NULL,pFirstLoop=NULL;

 VARIANT_BOOL pVBool,pCBool;

 LPEDGE pEdge=NULL;

 LPCURVE pCurve=NULL;

 char ch[128];

 short i;

 long pEdgeCount;

 

 //Form the return message

 *Message = "";

 

 //Get the selection mgr for this doc

 if(S_OK!=pModelDoc->get_ISelectionManager(&pSelectMgr)||pSelectMgr==NULL)

 {

  *Message+="Unable to get the Selection Manager.\r\n";

 }

else if(S_OK!=pSelectMgr->GetSelectedObjectType(1,&lres)||lres==0)

 {

  //Get the selected object type

  *Message+="No face is currently selected.\r\n";

 }

 else if(S_OK!=pSelectMgr->IGetSelectedObject2(1,&pUnk)||pUnk==NULL)

 {

  //Get the selected object of Unknown Type

  *Message+="Unable to get the selected object.\r\n";

 }

 else if(S_OK!=pUnk->QueryInterface(IID_IFace, (LPVOID *)&SelectedFace)||SelectedFace==NULL)

 {

  //Get the selected face

  *Message+="Unable to get the selected face.\r\n";

 }

 else if(S_OK!=SelectedFace->IGetFirstLoop(&pLoop)||pLoop==NULL)

 {

  //Get the selected loop

  *Message+="Unable to get the selected face first loop.\r\n";

 }

 else

 {

  pFirstLoop=pLoop;

  do

  {

   if(S_OK!=pLoop->IsOuter(&pVBool)||pVBool==TRUE)

   {

//    Check whether the loop is outer

    *Message+="The loop is an outer loop.\r\n";

   }

   else if(S_OK!=pLoop->GetEdgeCount(&pEdgeCount)||pEdgeCount<=0)

   {

//    Check the loop has edges, for example, no vertex loops.

    *Message+="The loop has no edges.\r\n";

   }

   else

   {

//  Allocate the calculated size edge list array and set them to null

    LPEDGE *pEdgeList = new LPEDGE[pEdgeCount];

    for (i=0;i<pEdgeCount;i++)

    {

     pEdgeList[i]=NULL;

    }

//    Get the edge list

    if(S_OK!=pLoop->IGetEdges(&pEdgeList)||*pEdgeList==NULL)

    {

     *Message+="Cannot get the loop edges.\r\n";

    }

    else

    {

//     Allocate the fixed size edge data array

     double* pEdgeData = new double[100];

 

//     Get the first edge in the list

     pEdge=pEdgeList[0];

 

     if(S_OK!=pEdge->IGetCurve(&pCurve)||pCurve==NULL)

     {

//      Get the curve

      *Message+="Cannot get the edge curve.\r\n";

     }

    else if(S_OK!=pEdge->IGetCurveParams2(&pEdgeData[0]))

     {

//      Get the data of curve

    *Message+="Failed to get the curve parameters.\r\n";

     }

     else

     {

//      Get the edge curve data

     if(S_OK!=pCurve->IsCircle(&pCBool)||pCBool==FALSE)

      {

//       the curve is not a circle

      *Message+="The curve is not a circle.\r\n";

      }

//      Increment the circular hole count

      else pCount=pCount+1;

     }

//     Release the curve

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

 

     delete pEdgeData;

 

    }

//    Release the allocated SOLIDWORKS edge list objects

    for (i=0;i<pEdgeCount;i++)

    {

     if(pEdgeList[i]!=NULL)pEdgeList[i]->Release();

    }

    delete pEdgeList;

   }

//  Get the next loop

 }while(S_OK==pLoop->IGetNext(&pLoop)&&pLoop!=NULL&&pLoop!=pFirstLoop);

  

  int t=sprintf(ch,"%d",pCount);

  CString pStr(ch);

  *Message+="The number of circular holes is " + pStr + ".\r\n";

 }

 

// Everything is okay.

// ========== == ===== =====

// Release the loop

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

// Release the selected face

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

// Release the Selection Manager

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

// Release the unknown object

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

// Return with report of results including errors

 return;

}



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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Circular Holes In Face Example (C++ COM)
*Comment:  
*   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:



x

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
x

Web Help Content Version: API Help (English only) 2017 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.