Jim Sculley

SaveAs for PDF hangs forever if file preview active in EPDM vault

Discussion created by Jim Sculley on Jun 21, 2019

SOLIDWORKS/EPDM 2017 SP5

 

 

Here is a simple test macro:

using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;

namespace SaveAsHangBug.csproj
{
    public partial class SolidWorksMacro
    {
        public void Main()
        {
            ModelDoc2 mDoc = swApp.ActiveDoc as ModelDoc2;
            ExportPdfData pdfData = (ExportPdfData)swApp.GetExportFileData((int)swExportDataFileType_e.swExportPdfData);
            string outputPath = @"<path to existing checked out PDF file in vault>";
            DispatchWrapper[] dispWrapArray = null;
            DrawingDoc dDoc = (DrawingDoc)mDoc;
            string[] sheetNames = (string[])dDoc.GetSheetNames();
            dispWrapArray = (DispatchWrapper[])wrapObjectArray(sheetNames);
            bool status = pdfData.SetSheets((int)swExportDataSheetsToExport_e.swExportData_ExportSpecifiedSheets, dispWrapArray);
            int errorCodes = 0;
            int warningCodes = 0;
            status = mDoc.Extension.SaveAs(outputPath, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, 0, pdfData, ref errorCodes, ref warningCodes);
        }
        /// <summary>
        /// Helper method for wrapping an object array into a dispatch array that COM can handle
        /// </summary>
        /// <param name="objects">The array of objects to be wrapped</param>
        /// <returns>The COM compatible dispatch array</returns>
        private static DispatchWrapper[] wrapObjectArray(object[] objects)
        {
            int ArraySize = 0;
            ArraySize = objects.GetUpperBound(0);
            DispatchWrapper[] d = new DispatchWrapper[ArraySize + 1];
            int ArrayIndex = 0;
            for (ArrayIndex = 0; ArrayIndex <= ArraySize; ArrayIndex++)
            {
                d[ArrayIndex] = new DispatchWrapper(objects[ArrayIndex]);
            }
            return d;
        }
        /// <summary>
        ///  The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;
    }
}

If you open a drawing in SOLIDWORKS and try to save it as a PDF via the API by running the above macro, it will hang forever if the PDF file already exists in the vault, is checked out and is active in the preview pane in a Windows Explorer window in the vault.

 

As soon as you select a different file or close the Windows explorer window, the SaveAs operation will complete successfully.

 

Before I submit this to my VAR, can someone using SW/EPDM 2019 verify that the problem still exists?

Outcomes