Set the visibility of all workplanes in a part

Top  Previous  Next

Here is how to set all the WorkPlanes in a part to be visible or invisible:

 

void SetVisibilityOfAllWorkPlanes (CComPtr<PartComponentDefinition>& pPartCompDef,

                                   const bool kbVisibility)

{

    // Get the list of workplanes in the part...

    CComPtr<WorkPlanes> pWorkPlanesList ;

    HRESULT hRes = pPartCompDef->get_WorkPlanes (&pWorkPlanesList) ;

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

        ShowCOMError (hRes,L"SetVisibilityOfAllWorkPlanes, could not get work planes list") ; 

        return ;

    }

 

    TRACE (L"There are %d workplanes\n",pWorkPlanesList->Count) ;

 

    const UINT ikNumWorkPlanes = pWorkPlanesList->Count ;

 

    VARIANT_BOOL vbVisib = kbVisibility ? VARIANT_TRUE : VARIANT_FALSE ;

 

    for (UINT i = 1 ; i <= ikNumWorkPlanes ; i++) {

        CComPtr<WorkPlane> pWorkPlane  ;

        hRes = pWorkPlanesList->get_Item(CComVariant(i),&pWorkPlane) ;

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

            ShowCOMError (hRes,L"SetVisibilityOfAllWorkPlanes, could not get item %d",i) ; 

            return ;

        }

        pWorkPlane->Visible = vbVisib ;

    }

}

 

You can write similar functions for WorkPoints and WorkAxes.

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