public static void AddCommand(string cmdGroupName, string cmdGlobalName, string cmdLocalName, CommandFlags cmdFlags, CommandCallback func);
how can use a function with params as the fifth param of this "AddCommand"method?
here goes the codes
[CommandMethod("Testaddcmd")]
static public void Testaddcmd()
{
Autodesk.AutoCAD.Internal.CommandCallback cc = new Autodesk.AutoCAD.Internal.CommandCallback ShowMsg());
Autodesk.AutoCAD.Internal.Utils.AddCommand("test", "ttt", "ttt", CommandFlags.Modal, cc);
}
public static void ShowMsg()
{
MessageBox.Show("ok:);
}
==========>the error one
[CommandMethod("Testaddcmd")]
static public void Testaddcmd()
{
Autodesk.AutoCAD.Internal.CommandCallback cc = new Autodesk.AutoCAD.Internal.CommandCallback ShowMsg("s"));
Autodesk.AutoCAD.Internal.Utils.AddCommand("test", "ttt", "ttt", CommandFlags.Modal, cc);
}
public static void ShowMsg(string s)
{
MessageBox.Show(s);
}
CommandCallback is just a delegate that takes no arguments and returns void.
public delegate void CommandCallback();
So just pass in a function that matches that signature.
[CommandMethod("Addcommand")] public void Addcommand() { Utils.AddCommand("poo", "poo", "poo", CommandFlags.Modal, poo); } void poo() { Application.ShowAlertDialog("poo"); }
Would probably make more sense to do it from Intialize instead of from a class already registered.