Suppression and Unsuppression of features

Top  Previous  Next

To suppress and unsuppress features in a part simply use the feature's suppression boolean:

 

   pFeature->put_Suppressed(true) ;

 

(Suppression of parts in an assembly has a different use).

 

Here is a function which will suppress a named part in a PartComponentDefinition:

 

void SetSuppressPartFeatureByName (CComPtr<PartComponentDefinition>& pPartCompDef,

                                  const wchar_t* const pszName,

                                  const bool bSuppress)

{

   TRACE (L"SetSuppressPartFeatureByName %s, %d\n",pszName,bSuppress) ;

 

   // Get the list of features...

   CComPtr<PartFeatures> pFeaturesList ;

   HRESULT hRes = pPartCompDef->get_Features(&pFeaturesList) ;

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

       ShowCOMError(hRes,L"SetSuppressPartFeatureByName get_Features failed");

       return ;

   }

 

   const long ikNumFeats = pFeaturesList->GetCount() ;

 

   TRACE (L"    There are %d pattern features\n",ikNumFeats) ;

 

   bool bDone = false ;

 

   for (long iFeat = 1 ; iFeat <= ikNumFeats ; iFeat++) {

       CComPtr<PartFeature> pFeature ;

       hRes = pFeaturesList->get_Item (CComVariant(iFeat),&pFeature) ;

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

           ShowCOMError(hRes,L"SetSuppressPartFeatureByName get_Item failed");

           return ;

       }

 

       BSTR bstrName ;

       pFeature->get_Name (&bstrName) ;

 

       if (_wcsicmp (bstrName,pszName) == 0) {

           if (bSuppress) {

               pFeature->put_Suppressed (VARIANT_TRUE) ;

               TRACE (L"Found Feature %d called %s to be suppressed\n",iFeat,bstrName)  ;

 

           } else {

               pFeature->put_Suppressed (VARIANT_FALSE) ;

               TRACE (L"Found Feature %d called %s to be unsuppressed\n",iFeat,bstrName)  ;

           }

           bDone = true ;

       }

 

       ::SysFreeString (bstrName) ;

 

       if (bDone) {

           break ;

       }

   }

 

   if (!bDone) {

       TRACE (L"Could not suppress feature by name with name = <%s>\n",pszName) ;

   }

}

 

Within a single RectangularPattern (or any other pattern) you can use this fragment as a starting point.

 

In some circumstances Suppressed=VARIANT_FALSE will crash while put_Suppressed (VARIANT_FALSE) will not. A mystery wrapped inside an enigma. I always use put_Suppressed.

 

Note that you'll need to call Update to refresh the display:

 

   pPartDocument->Update () ; // Like an AutoCAD regen

 

You cannot suppress all types of objects. You cannot, for example, suppress workpoints.

 

 

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