Save programatically

Top  Previous  Next

The Save function can be used like this:

 

   CComQIPtr<AssemblyDocument> pAssemblyDoc ;

   ...init pAssemblyDoc ...

   CString csFullAssemblyName (L"C:\\TEST_DIR\\Test_Assembly.iam") ;

   pAssemblyDoc->put_FullFileName (CComBSTR(csFullAssemblyName)) ;

   pAssemblyDoc->Save () ;

 

Note that in this example I've changed the full filename of the assembly, and then called Save.

 

If the file already exists then a Save dialog will pop up, otherwise the save will run silently. Save will not silently overwrite an existing file, check the return value if you find your changes are not being saved.

 

Note also that if the doc is new, and so does not have a name, the Save will fail with error 80004005. This is because of the empty filename. Here is an example of avoiding that error:

 

   /*

    * This is a new drawing and so had no name. Without a name

    * the Save function will not work. So set the name...

    */

   CString csFullIDWName (kcsFullAssemblyName) ;

   ChangeExtension (csFullIDWName,L"IDW") ;

   pDrawingDoc->put_FullFileName (CComBSTR(csFullIDWName)) ;

 

   /*

    * Now you can save, since the doc has a name

    */

   hRes = pDrawingDoc->Save () ;

   if (FAILED(hRes)) {

       // Check anyway...

       CComBSTR bstrFullFileName ;

       pDrawingDoc->get_FullFileName (&bstrFullFileName) ;

       ShowCOMError (hRes,L"Saving drawing document <%s>",bstrFullFileName) ;

   }

 

See also SaveAs, which allows you to specify overwrite and saves a copy.

 

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