.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Utils.AddCommand() function with params

2 REPLIES 2
Reply
Message 1 of 3
275171906
863 Views, 2 Replies

Utils.AddCommand() function with params

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

2 REPLIES 2
Message 2 of 3
FRFR1426
in reply to: 275171906

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
Message 3 of 3
jeff
in reply to: FRFR1426

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost