Add a DrawingSketch to a DrawingDocument

Top  Previous  Next

Here's a function for doing that:

 

// Add a sketch with the given name to the DrawingDocument

bool AddSketchToIDW(CComPtr<DrawingSketch>& pDrawingSketch// return value

                   CComQIPtr<DrawingDocument>& pDrawingDoc, // In which doc to add the sketch

                   const CString& kcsNewSketch) // Name of the new sketch

{

   // Find the sheets of the drawing document...

   CComPtr<Sheets> pSheets = nullptr ;

   HRESULT hRes = pDrawingDoc->get_Sheets(&pSheets) ;

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"ASTI, could not get sheets of drawing document.");

       return false ;

   }

 

   // Get the (assumed) single sheet inside the IDW. Remember the first object

   // in a COM list has index 1...

   CComPtr<Sheet> pSheet = nullptr ;

   hRes = pSheets->get_Item (CComVariant(1),&pSheet) ;

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"ASTI, could not get 1st sheet of drawing.");

       return false ;

   }

 

   // Get hold of the list of drawing sketches of this sheet...

   CComPtr<DrawingSketches> pSketches = nullptr ;

   hRes = pSheet->get_Sketches(&pSketches);

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"ASTI, could not get drawing sketches.");

       return false ;

   }

 

   // Add a new drawing sketch

   // CComPtr<DrawingSketch> pDrawingSketch  ;

   hRes = pSketches->Add(&pDrawingSketch);

   if (FAILED(hRes)) {

       ShowCOMError (hRes,L"ASTI, could not aad sketch.");

       return false ;

   }

 

   pDrawingSketch->put_Name(CComBSTR(kcsNewSketch));

 

   return true ;

}

 

 

Here's an example of adding lines and text to a drawing sketch..

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