AnsweredAssumed Answered

[C#] Saving multiple drawings as PDF crashes SolidWorks

Question asked by Jakub Smatelka on Mar 30, 2016
Latest reply on Mar 30, 2016 by Artem Taturevych

Hi,

I have a C# app that goes through many files (ca 1000) and exports them to our IS. It gets PNG preview, BOM and drawing saved as PDF if it exists. The part saving drawing as PDF sometimes causes solidworks to crash.

 

Is this known issue? Is there any workaround?

I am running Solidworks 2015 and Windows 7 Professional.

 

Code saving PDF for a drawing - called once per drawing.

 

            SldWorks solidworksApplication = new SldWorks();

            int errors = 0;

            int warnings = 0;

            try {

                ModelDoc2 document = solidworksApplication.OpenDoc6(

                    AbsolutePath,

                    (int)swDocumentTypes_e.swDocDRAWING,

                    (int)swOpenDocOptions_e.swOpenDocOptions_Silent,

                    "", ref errors, ref warnings);

                ModelDocExtension documentExtension = document.Extension;

                DrawingDoc drawing = (DrawingDoc)document;

                ExportPdfData exportPdfData =

                    (ExportPdfData)

                        solidworksApplication.GetExportFileData((int)swExportDataFileType_e.swExportPdfData);

                exportPdfData.ViewPdfAfterSaving = false;

 

 

                exportPdfData.SetSheets((int)swExportDataSheetsToExport_e.swExportData_ExportAllSheets,

                    drawing.GetSheetNames());

 

                // here it stops and windows reports that Solidworks stopped working

                var result = documentExtension.SaveAs(

                    pdfFilepath,

                    (int)swSaveAsVersion_e.swSaveAsCurrentVersion,

                    (int)swSaveAsOptions_e.swSaveAsOptions_Silent,

                    exportPdfData, ref errors, ref warnings);

 

                if (!result)

                {

                    throw new InvalidOperationException("PDF nelze vygenerovat: " + AbsolutePath);

                }

            } finally

            {

                solidworksApplication.CloseAllDocuments(true);

            }

 

Thanks

Outcomes