What is the best way to call a macro from a button (click) on a C# form...i've been looking through & have not fount anything.
Your question is broad. You need to define the context of your application so people can help you.If I understood you correctly, you may achieve that by using the Isldworks.RunMacro2 method from inside your button event handling method in C#.
You mean to call macro from a C# addin or stand alone ?
Yes, in a C# Addin. for a Task Pane
if yes then I think it's much simple to integrate the macro into the addin
As I have issue to maintain the macro ref. for each new SW release
that might be fine with some of the simpler macro, & ones that don't change too often, but i have a few large ones, that would just be cleaner to just initiate the macro from a button on the custom addin task bar
This might be help
Ya I seen that, and also the references on that page, ( http://help.solidworks.com/2013/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.ISldWorks~RunMacro2.html ) however the reference on the top & the Example on the bottom have different syntax (confusing)...and my debugger is still kicking it out...either way
Here's some example syntax that might help. Make sure that swApp is already declared and connected to SolidWorks and your macro path, module and procedure names are set.
String macroPath = "C:\\Macros\\SomeMacro.swp";
String moduleName = "";
String procedureName = "Main";
boolstatus = swApp.RunMacro2(macroPath, moduleName,
procedureName, 0, out runMacroError);
So i haven't been looking at this, and now i have gotten back around to it.
It builds fine, however it crashed out SW with “SLDWORKS.exe' has exited with code 1 (0x1)”
Seems so simple to me and yet it is my last hurdle to bet my new taskpane running
public partial class SWTaskpaneHost : UserControl
public const string SWTASKPANE_PROGID = "Rv.SWTaskPane_SwAddin";
public SldWorks swApp;
private void button1_Click(object sender, EventArgs e)
string macroPath = "D:\\RV\\Solidworks Custom Paths\\Macros\\RV\\Red Viking Custom Property.swp";
string moduleName = "MainModule";
string procedureName = "main";
boolstatus = swApp.RunMacro2(macroPath, moduleName, procedureName, 0, out runMacroError);
private void button2_Click(object sender, EventArgs e)
string macroPath = "D:\\RV\\Solidworks Custom Paths\\Macros\\RV\\Private\\Solidworks RV Toolbar\\assytreesort\\Sort - DesignTree.swp";
string moduleName = "SortDesignTree1";
Retrieving data ...