Making workfeatures of a part invisible in the assembly

Top  Previous  Next

Work features which are exported are in a table based iPart are often visible in the assembly into which the part is placed. It seems to be the default action.

 

To make these work features invisible in the assembly you need to use a function like this:

 

// pOcc is the occurrence of a part in an assembly. This function which switch on or off

// the visibility of a workplane of the part in the assembly. It does not affect the

// visibility in the part file.

void SetWorkPlaneVisibility(CComPtr<ComponentOccurrence>& pOcc, const CString& kcsWorkPlaneName, const bool kbVisible)

{

   CComPtr<ComponentDefinition> pDef = nullptr;

   HRESULT hRes = pOcc->get_Definition(&pDef);

   if (FAILED(hRes)) {

       ShowCOMError(hRes, L"SWPV could not get definition %s",kcsWorkPlaneName);

       return;

   }

 

   CComQIPtr<PartComponentDefinition> pPartCompDef = pDef;

 

   CComPtr<WorkPlane> pWorkPlane=nullptr ;

   hRes = pPartCompDef->WorkPlanes->get_Item(CComVariant (kcsWorkPlaneName),&pWorkPlane);

   if (FAILED(hRes)) {

       ShowCOMError(hRes, L"SWPV, could not get workplane called %s",kcsWorkPlaneName);

       return;

   }

 

   // Get the proxy which is how the part is instantiated in the assembly

   CComPtr<WorkPlaneProxy> pWPProxy ;

   hRes = pOcc->CreateGeometryProxy (pWorkPlane,(IDispatch**)&pWPProxy) ;

   if (FAILED(hRes)) {

       ShowCOMError(hRes, L"Could not get proxy of %s",kcsWorkPlaneName);

       return;

   }

 

   if (kbVisible) {

       hRes = pWPProxy->put_Visible(VARIANT_TRUE);

 

   } else {

       hRes = pWPProxy->put_Visible(VARIANT_FALSE);

   }

 

   if (FAILED(hRes)) {

       ShowCOMError(hRes, L"Could not get set proxy visibility of %s",kcsWorkPlaneName);

   }

}

 

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

 

 

 

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