I want to create an add-in that can automate some of our workflow in SolidWorks CAM 2021. According to this help page, it is possible to access the API of other addins: https://help.solidworks.com/2018/English/api/sldworksapiprogguide/Overview/Accessing_Add-ins.htm
However I'm not sure what to do after using GetAddInObject on the SolidWorks CAM addin. This guy seem to have a solution for VB, but doesn't present the actual implementation.
This is the code I have so far:
dynamic SWCAMObject = default(dynamic);
dynamic SWCAM = default(dynamic);
SWCAMObject = iSwApp.GetAddInObject("{CCAC6208-0E19-6455-2017-2021CEB541FA}");
if (SWCAMObject == null) ErrorMsg(iSwApp, "SWCAMObject object not found");
Debug.WriteLine($"SWCAMObject loaded: {SWCAMObject}");
SWCAM = SWCAMObject.CAMWORKSADDINLib; <---- Breaks here, not at all sure how to extract the addin interface.
if (SWCAM == null) ErrorMsg(iSwApp, "SWCAM object not found");
Debug.WriteLine($"SWCAM loaded: {SWCAM}");
Does anyone know how to extract the Solidworks CAM interface correctly?
Question has also been asked here: https://forum.solidworks.com/thread/246718
--- Update --- Following Sinues advice works! I can't add the dll's he's referring to, I get the following error: "... could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component." However i've added the COM references: SOLIDWORKS CAM 2021 Type Library CAMWorksAddin 1.0 Type Library And this seem to work
My final code which is running is:
CAMWORKSADDINLib.MWAddin addinObject = iSwApp.GetAddInObject(@"{CCAC6208-0E19-6455-2017-2021CEB541FA}");
if (addinObject == null) ErrorMsg(iSwApp, "SWCAMObject object not found");
Debug.WriteLine($"SWCAMObject loaded: {addinObject}");
CAMWORKSLib.CWApp cwApp = addinObject.GetCWApp();
if (cwApp == null) ErrorMsg(iSwApp, "SWCAM object not found");
Debug.WriteLine($"SWCAM loaded: {cwApp}");
Debug.WriteLine(cwApp.GetVersion());
First you have to add a reference to the following DLL files to gain access to intellisense:
Then you can get the addin object as you already did but as a specific object (MWAddin):
CAMWORKSADDINLib.MWAddin addinObject = swApp.GetAddInObject(@"{CCAC6208-0E19-6455-2017-2021CEB541FA}");
And to access the interface API (of cwapiu.dll):
CAMWORKSLib.CWApp cwApp = addinObject.GetCWApp();
From here you will work with the cwApp object and the object types of the CAMWORKSLib library