Solidworks CAM API development

I would like to develop a macro to simplify the workflow for solidworks cam. There is not too much resources I can find on line. The official API indicates that:
The C:\SOLIDWORKSCAMData\xxxx\API_Macros folder contains macros that have been developed based on SOLIDWORKS CAM API’s.
But I could not find such folder. Does anyone have any experience with this?

1 Like

Very interesting question.

I have no experience with CAM but there are different avenues of automation to explore…

GetAddInObject returns an object that represents the add-in and can be used to automate the function of the add-in. I don’t have CAM installed so I do not have access to the documentation…

You need to have SOLIDWORKS CAM Professional(additional charge not the one that comes with SOLIDWORKS) or you need to have a CAMWorks license to use the API. Hope that helps.

1 Like

Welcome back, @Gklein ! Took you 11 months to come back here :frowning:

Thanks Gklein. I do have solidworks CAM professional. Do you happen to have any example code to start with? I checked with my reseller and they can not provide any resources either.

3d Content Central has some Cam related macros examples which you can look at.

1 Like

Hi there. I managed to automate some operations in Solidworks cam, using SolidWorks standard license and a stand-alone program with CadBooster framework in C#. Here is how I did it. First you need to include CAMWORKSADDINLib, and then you create an object of type MWAddin:
MWAddin addinObject = (MWAddin)Globals.swApp.UnsafeObject.GetAddInObject(FindSolidCAMAddIn());

FindSolidCamObject is a function that searches the registry for the add-in guid:
private static string FindSolidCAMAddIn()
RegistryKey AddInKey = Registry.CurrentUser.OpenSubKey(“SOFTWARE\SolidWorks\AddInsStartup”);

        if (AddInKey != null)
            foreach (string subKeyName in AddInKey.GetSubKeyNames())
                if (subKeyName.StartsWith("{1f4a9ee8"))

                    // You found the key, return the formatted key name
                    return subKeyName;

        return "";

Once you have your object, you have to get the CAMWorks app like this:
CWApp cwApp = addinObject.GetCWApp();
And then you work from here. This is an example I did, where I collected all the machinable features, created the operation plan, and ran the simulation.
public static void SetupCAMOperations()
CWDoc cwDoc = Globals.cwApp.IGetActiveDoc();
CWPartDoc cwPart = (CWPartDoc)cwDoc;
CWMillMachine cwMillMachine = cwPart.IGetMachine();
ICWMachine5 cwMachine = (ICWMachine5)cwMillMachine;

ICWDispatchCollection collection = cwMachine.IGetEnumSetups();
CWBaseSetup cwBaseSetup = collection.Item(0);



I also suggest taking a look at the Solidworks cam help file, which is located under Help(question mark icon top right corner) → SOLIDWORKS CAM → API help

1 Like

@KraljMatjaz : Great find man! Post it as a separate post and add more content to it!