Utils.AddCommand() function with params

Utils.AddCommand() function with params

275171906
Contributor Contributor
1,448 Views
2 Replies
Message 1 of 3

Utils.AddCommand() function with params

275171906
Contributor
Contributor

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);
}

0 Likes
1,449 Views
2 Replies
Replies (2)
Message 2 of 3

FRFR1426
Collaborator
Collaborator
Commands can not have parameters. Period.

So what you are trying to do can not works. Use a Lisp function instead or use Editor.Getxxx functions to get user input which is the equivalent of parameters in the context of a command.
Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr
0 Likes
Message 3 of 3

jeff
Collaborator
Collaborator

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. 

You can also find your answers @ TheSwamp
0 Likes