Interrogating rectangular patterns

Top  Previous  Next

Here is a rectangular pattern inside an assembly:




If you have a PartComponentDefinition which contains a RectangularPatternFeature use this fragment of code to find out basic data:


    CComPtr<PartFeatures> pFeatures  ;

    hRes = pBlockCompDef->get_Features (&pFeatures) ;


    CComPtr<RectangularPatternFeatures> pRectPatList  ;

    hRes = pFeatures->get_RectangularPatternFeatures (&pRectPatList) ;


    // Pretend we know that we want the first rectangular pattern...

    CComPtr <RectangularPatternFeature> pRectPatFeat  ;

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


    CComPtr<Parameter> pXCountParam ; 

    pRectPatFeat->get_XCount (&pXCountParam) ;

    int iXCount = 1 ; // note this initialization!

    if (pXCountParam != nullptr) {

        iXCount = pXCountParam->GetValue () ; // only if not nullptr!



    CComPtr<Parameter> pYCountParam ; 

    pRectPatFeat->get_YCount (&pYCountParam) ;

    int iYCount = 1 ; // note this initialization!

    if (pYCountParam !=nullptr) {

        iYCount = pYCountParam->GetValue () ; // only if not nullptr!



    TRACE (L"The rectangular feature has %d by %d items\n",iXCount,iYCount) ;


Note the strangeness of the fact that there is no Y count if the pattern is a linear array with , for example, 5 X items. That is why I set iYCount to 1 and change it only if pYCountParam is not nullptr.


Note also that you should check hRes, I've not done it for clarity here.




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