Hi Thomas, there are many posts on the forum about macros saving PDFs, DXFs, and DWG files... here are a couple:
Generally macros are not automatically ran. Depending on if you wanted it to run daily, triggered when a file is saved or some other event... you could either create a program (.exe) or an add-in to do what you want.
I would also suggest reviewing the examples posted here:
A bunch of api examples:
You may also set up the task scheduler to run the macro.
Thanks for your help guys have been looking through examples but unfortunately most are in VBA not C#. I wouldn't say I know C# but have some experience in it.
I have made a macro which works but before letting it loose on all my drawings (not just a copy of a few) would someone be able to check that it is coded as it should be and nothing is going to go wrong?
public partial class SolidWorksMacro
public void Main()
string drwPaths = System.IO.Directory.GetFiles("C:\\Users\\SAFEROADS201\\Desktop\\01-VMS Trailer\\Drawings", "*.slddrw", SearchOption.AllDirectories);
foreach (string s in drwPaths)
ModelDoc2 swDoc = null;
int longstatus = 0;
int longwarnings = 0;
pdfPath = s;
pdfPath = pdfPath.Replace("Drawings", "PDFs").Replace("SLDDRW", "PDF");
swDoc = ((ModelDoc2)(swApp.OpenDoc6(s, 3, 0, "", ref longstatus, ref longwarnings)));
longstatus = swDoc.SaveAs3(pdfPath, 0, 0);
swDoc = null;
/// The SldWorks swApp variable is pre-assigned for you.
public SldWorks swApp;
Thanks for the tip on the task manager too that will be a very easy way to do it.
You will probably want to learn VBA if you want to seriously use the API. Most of the learning resources as well as examples are in VBA. I talk about this some in this blog post: 7 Mistakes New SolidWorks API Programmers Make. It's only my opinion, of course, but if you're trying to save time in the long run then this is the way to go. I don't think you'll find VBA very hard to pick up if you already know some C#.
I also explain how to use the Task Scheduler to run macros here.
Thanks Kieth, I probably won't use it very often I work for a very small company so mostly what I do is pretty simple but varied and not worth automating really. If I use it more often than I thought I'll probably learn VB but for one or two things I'm doing its easier to just stick with C#