Listing the contents of Patterns

Top  Previous  Next

The parent objects of a Pattern are the objects selected to be repeated in the pattern. They could also be called source objects...

 

PatternDetails

 

Here are a couple of functions illustrating how to get details from patterns:

 

// Write out details of any rectangular patterns in this assembly

void ListRectPatterns(CComPtr<AssemblyComponentDefinition>& pAsmCompDef)

{

   gLogger.Printf(ekLogMsg, L"LRP starting...");

   CComPtr<OccurrencePatterns> pOccPatterns;

   pOccPatterns = pAsmCompDef->GetOccurrencePatterns();

   if (pOccPatterns == nullptr) {

       gLogger.Printf(ekLogMsg, L"LRP no patterns...");

       return ;

   }

 

   for (int p = 1; p <= pOccPatterns->Count; p++) {

       gLogger.Printf(ekLogMsg, L"LRP pattern %d...",p);

       CComPtr<OccurrencePattern> pPattern;

       CComVariant varp(p);

       HRESULT hRes = pOccPatterns->get_Item(varp, &pPattern);

       if (FAILED(hRes) || (pPattern == nullptr)) {

           gLogger.Printf(ekLogMsg, L"LRP could not get %d...",p);

           continue;

       }

 

       CComQIPtr<RectangularOccurrencePattern> pRectPattern;

       pRectPattern = pPattern;

       if (pRectPattern == nullptr) {

           continue;

       }

 

       // Getting hold of the row and column counts is a bit tricky...

       CComVariant varRowCount (pRectPattern->RowCount->GetValue());

       CComVariant varColCount (pRectPattern->ColumnCount->GetValue());

 

       // Name of the pattern

       const CString kcsPatternName (pRectPattern->Name.GetBSTR());

       const UINT ikNumSubItems = int(varRowCount.dblVal * varColCount.dblVal);

 

       gLogger.Printf (ekLogMsg,L"Rect Pattern <%s> has %.1f rows and %.1f columns, numsub items=%d",

                       kcsPatternName,varRowCount.dblVal,varColCount.dblVal,ikNumSubItems);

 

       // Parent components are the objects which are the source objects of the array.

       CComPtr<ObjectCollection> pParentComponents;

       hRes = pRectPattern->get_ParentComponents(&pParentComponents);

       if (FAILED(hRes) || (pParentComponents == nullptr)) {

           gLogger.Printf(ekLogMsg, L"Could not get parent objects");

           continue;

       }

 

       // Now list the parent objects

       gLogger.Printf(ekLogMsg, L"LRP pattern %d has %d parent objects...",p,pParentComponents->Count);

 

       for (int o = 1; o <= pParentComponents->Count ; o++) {

           CComQIPtr <ComponentOccurrence> pOcc;

           hRes = pParentComponents->get_Item (o,(IDispatch**)&pOcc);

           if (FAILED(hRes) || (pOcc == nullptr)) {

               gLogger.Printf(ekLogMsg, L"Skipping sources object %d %d", p, o);

               continue;

           }

 

           _bstr_t DisplayName = pOcc->Get_DisplayName();

           CString kcsDisplayName = CString (DisplayName.GetBSTR());

 

           gLogger.Printf(ekLogMsg, L"Pattern %03d parent occurrence %03d is <%s>", p, o, kcsDisplayName);

       }

   }

}

 

/*****************************************************************************************/

 

// List the features of any rectangular patterns in this part

void ListRectPatternFeatures (CComPtr<PartComponentDefinition>& pPartCompDef)

{

   HRESULT hRes ;

 

   // Get the list of features...

   CComPtr<PartFeatures> pFeaturesList ;

   pPartCompDef->get_Features(&pFeaturesList) ;

 

   // Get the list of rectangular features, we will add to this list....

   CComPtr<RectangularPatternFeatures> pRectPatList ;

   pFeaturesList->get_RectangularPatternFeatures (&pRectPatList) ;

 

   const long ikNumRecFeats = pRectPatList->GetCount() ;

 

   for (int iRect = 1 ; iRect <= ikNumRecFeats ; iRect++) {

 

       CComPtr <RectangularPatternFeature> pRectPatFeat ;

       hRes = pRectPatList->get_Item (CComVariant(iRect),&pRectPatFeat) ;

 

       if (FAILED(hRes)) {

           ShowCOMError (hRes,L"ListRectangularPatternComponents, could not get rectangular pattern") ;

           return ;

       }

 

       BSTR bstrName = pRectPatFeat->GetName () ;

 

       CComPtr<Parameter> XCountParam ;

       pRectPatFeat->get_XCount (&XCountParam) ;

       /*const int ikXCount = XCountParam->GetValue () ;

 

       TRACE (L"Component %d is called %s, and the x count is %d ",iRect,bstrName,ikXCount) ;*/

 

       CComPtr<FeaturePatternElements> pFeaturePatternElements ;

       pRectPatFeat->get_PatternElements (&pFeaturePatternElements) ;

 

       const int ikNumElements = pFeaturePatternElements->GetCount() ;

       TRACE (L", this has %d FeaturePatternElements\n",ikNumElements) ;

 

       for (int iElem = 1 ; iElem < ikNumElements ; iElem++) {

           CComPtr<FeaturePatternElement> pFeaturePatternElement ;

           pFeaturePatternElements->get_Item (iElem,&pFeaturePatternElement) ;

       }

 

       ::SysFreeString(bstrName);

   }

}

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)