Looping over views in sheets

Top  Previous  Next

This function will find a named view in a sheet of an IDW:

 

bool FindDrawingViewInSheetByName (CComPtr<DrawingView>& pView,

                                  CComPtr<Sheet>& pSheet,

                                  const wchar_t* const pszName)

{

   if ((pSheet == nullptr) || (pszName == nullptr) || (wcslen (pszName) == 0)) {

       TRACE (L"FindDrawingViewInSheetByName, Bad input parameters") ;

       return false ;

   }

 

   CComPtr<DrawingViews> pViews  ;

   HRESULT hRes = pSheet->get_DrawingViews (&pViews) ;

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

       ShowCOMError (hRes,L"FindDrawingViewInSheetByName, get_DrawingViews failed.");

       return false ;

   }

 

   const long ikNumViews = pViews->GetCount() ;

   for (long iView = 1 ; iView <= ikNumViews ; iView++) {

       CComPtr<DrawingView> pThisView  ;

       hRes = pViews->get_Item (iView,&pThisView) ;

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

           ShowCOMError (hRes,L"FindDrawingViewInSheetByName, get_Item(%d) failed.",iView);

           return false ;

       }

 

       CComBSTR bstrViewName ;

       pThisView->get_Name (&bstrViewName) ;

 

       TRACE ("Found a view called %s\n",bstrViewName) ;

 

       if (wcscmp(CString(bstrViewName),pszName) == 0) {

           pView = pThisView ;

           return true ;

       }

   }

 

   return false  ;

}

 

 

So you can find a named view inside a sheet..

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