1 Reply Latest reply on Mar 30, 2016 6:13 PM by Artem Taturevych

    [C#] Saving multiple drawings as PDF crashes SolidWorks

    Jakub Smatelka


      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(




                          "", ref errors, ref warnings);

                      ModelDocExtension documentExtension = document.Extension;

                      DrawingDoc drawing = (DrawingDoc)document;

                      ExportPdfData exportPdfData =



                      exportPdfData.ViewPdfAfterSaving = false;






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

                      var result = documentExtension.SaveAs(




                          exportPdfData, ref errors, ref warnings);


                      if (!result)


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


                  } finally






        • Re: [C#] Saving multiple drawings as PDF crashes SolidWorks
          Artem Taturevych

          Hi Jakub,


          This is unfortunately a known issue. Not all resources released when you close the file. So depending on this size of the files and your system resources you will eventually get SolidWorks to crash. For that reason we have developed a batch macro running utility called #TASK.


          The utility takes care of crashes  and hangs of SolidWorks and automatically restarts and continues the work if needed. Furthermore it can automatically restart SolidWorks every n-files just to free the resources (we have noticed that after some number of files the system slows down and it is better to restart).


          You can run your own macros in there as well as use the one from the online library.We already have the 'Save PDF'  task in there. So if you just need to convert your drawing in a batch #TASK would help but if you developing a bigger application you have to implement the events system watcher to catch SolidWorks crash/hang and restart.