ACTION BUTTONS
The action buttons are powerful tool that you can use to automatically set parameters and running commands with a simple click.
They are located under the parameter inputs in the GUI, and can be customized by adding specific methods inside your command code.
To add an Action Button:
1. Select a command and edit its code.
2. Locate the [[KEEP_BLOCK]] section after the ExecuteRoutine method.
3. Inside the [[KEEP_BLOCK]] section insert the following code:
public static void myActionButton(CommandConsoleGUIElement guiElement) { //Your button logic goes here.... //... //... }
NOTE: Always place your code inside the [[KEEP_BLOCK]] tags, otherwise it will not be kept when you recompile the command. (See Creating Commands for more details)
NOTE: Never delete a [[KEEP_BLOCK]] tag.
4. To Set a parameter value when clicking the button use the guiElement.SetParameter() methods:
public static void myActionButton(CommandConsoleGUIElement guiElement) { //Sets 42 as value of the parameter named myIntParam. guiElement.SetParameter("myIntParam", 42); //Sets true as value of the parameter named myBoolParam. guiElement.SetParameter("myBoolParam", true); //Sets "green" as value of the immediate parameter (named "color"). guiElement.SetParameter("color", "green"); //Sets the value with index 1 from the possible values of the immediate parameter (named "color"). guiElement.SetParameter("color", 1); }
5. You can also get current parameter values in the GUI Input Fields by using the guiElement.GetParameter() methods:
public static void myActionButton(CommandConsoleGUIElement guiElement) { //Gets the current value of the parameter named "id". object idValue = guiElement.GetParameter("id"); //GetParameter return generic object values, you should always check againts null and speficic type-casting when using them. if (idValue != null && idValue is int) { int id = idValue; //... //... } }
6. You can change the return type of the action button method from void to bool and return true if you want to automatically run the command when you click the action button.
public static bool myActionButton(CommandConsoleGUIElement guiElement) { //... //... //... return true; //The command will be executed automatically when clicking the action button. }