14 Replies Latest reply on Jan 29, 2016 12:55 AM by Artem Taturevych

    C# macro doesn't work anymore

    Thomas Hotchkin

      Hi all,


      So I wrote up this macro last year to convert bulk drawings into PDFs and since upgrading to 2015 it doesn't work. Any chance someone could have a quick look and tell me whats wrong with it or a better way to do this? It's only a tiny bit of code. It doesn't get an error or anything I run it and it just doesn't do anything.





      using SolidWorks.Interop.sldworks;
      using SolidWorks.Interop.swconst;
      using System.Runtime.InteropServices;
      using System;
      using System.IO;
      namespace PDF.csproj
          public partial class SolidWorksMacro
              public void Main()
                  string pdfPath;
                  string Path = "C:\\Solidworks\\05-Portable Safety Barriers\\13-T Lok Screen 5.4m";
                  string txtPath = Path + "\\UpdatedPDFs.txt";
                  //string Date = DateTime.Now.ToShortDateString();
                  string[] drwPaths = System.IO.Directory.GetFiles(Path, "*.SLDDRW", SearchOption.AllDirectories);
                  foreach (string s in drwPaths)
                      if (!s.Contains("~$"))
                          ModelDoc2 swDoc = null;
                          int longstatus = 0;
                          int longwarnings = 0;
                          pdfPath = s;
                          pdfPath = pdfPath.Replace("Drawings", "PDFs").Replace("SLDDRW", "PDF");
                          (new FileInfo(pdfPath)).Directory.Create();
                          swDoc = ((ModelDoc2)(swApp.OpenDoc6(s, 3, 1, "", ref longstatus, ref longwarnings)));
                          longstatus = swDoc.SaveAs3(pdfPath, 0, 0);
                          swDoc = null;
                  //System.IO.File.WriteAllText(txtPath, Date);
              /// <summary>
              ///  The SldWorks swApp variable is pre-assigned for you.
              /// </summary>
              public SldWorks swApp;