Using the API to properly save a drawing - trying to activate each sheet before saving.

I've written a batch process in an external c# app to change some custom properties in SolidWorks drawings and then it sends them off to another process that handles PDF creation (the process uses "Quick View").  Sometimes the PDF version of a multi-sheet drawing is missing views.  To remedy this someone has to manually open the drawing, activate each sheet, resave and then send it off to the PDF generator again.  This is mentioned here http://www.lennyworks.com/solidworks/default.asp?ID=26 so I guess it's normal:

  • When saving a multi sheet drawing, manually activate each sheet to force a rebuild to ensure all sheets show the proper information when the drawing is opened in SolidWorks's 'View Only' mode or opened in the SolidWorks Viewer.

I've tried to mimic this in the API like this (barebones process):

'Open the drawing for manipulation of the properties

uSwDoc = (SwDMDocument)uSwDocMgr.GetDocument(workingFileName, uNDocType, false, out uNRetVal);

     ...{property changes}

uSwDoc.Save();

uSwDoc.CloseDoc();

'To rebuild the document I open it again using ModelDoc2

uModDoc = (ModelDoc2)uSldWorks.OpenDoc6(workingFileName, (int)uNDocType, 17, "", ref Errors, ref Warnings);

'I also capture the document as DrawingDoc so I can go through the sheets

uDrawDoc = uSldWorks.ActiveDoc;

'Activate each sheet

sheetNames = uDrawDoc.GetSheetNames();

           

            foreach (string sheet in sheetNames)

            {

                uDrawDoc.ActivateSheet(sheet);

            }

'Finally rebuild and save

uModDoc.ForceRebuild3(true);

uModDoc.Save3(1, ref Errors, ref Warnings);

This is just the way I've done it, I'm sure there's probably a more efficient way, but I haven't found it yet and obviously it's not working too well for me!

Very open to a new method!

SolidworksApi macros