Home > MacrosEngine Addons Dev Guide

MacrosEngine Addons Dev Guide

Get Started:

To get started with building addons for MacrosEngine, first create a visual studio .net class library project, and then reference the IMacrosData.dll in your project (found in the MacrosEngine installation folder), make sure the targeted .NET framework is 4.6.

Creating a Task Action:

To create a task action, create a new class and reference the interface IMacrosTask and implement all it's members.

Task Action Example Code:

//make sure to reference the IMacrosTask in your class and implement all it's childs.
    public class DebugInput : IMacrosTask
    {
        //this is the name of your task action, make sure it's unique
        public string MethodName { get { return "Debug Message"; } }
        //this is the category where your task action belongs, can be anything you want.
        public string Category { get { return "Debugging"; } }

        public DebugInput()
        {
            this.Properties = new List<NodeProperty>();
            //Adding a NodeProperty to the list of properties, a NodeProperty can have multiple types
            //The line below is for adding a Message textbox property to the current task action
            this.Properties.Add(new NodeProperty("Message", ControlPropertyType.Text));
            //the line below is to add a type combobox property with 3 values
            NodeProperty node = new NodeProperty("Type", ControlPropertyType.ComboBox);
            node.ValuesList = new []{"Error","Info", "Debug" };
            this.Properties.Add(node);
        }

        //ExecuteFunction will contain your code logic, where your code will execute when the task action is executed.
        //Params contains the list of node properties and their set values, exp: Params["Message"]
        // helper object of type IMacrosHelper will contain all the helper functions and properties to help you
        // access MacrosEngine environment
        public void ExecuteFunction(IMacrosHelper helper, Dictionary<string, string> Params)
        {
            switch (Params["Type"])
            {
                case "Error":
                    helper.logger.Error(Params["Message"]);
                    break;
                case "Info":
                    helper.logger.Info(Params["Message"]);
                    break;
                case "Debug":
                    helper.logger.Debug(Params["Message"]);
                    break;
                default:
                    helper.logger.Debug(Params["Message"]);
                    break;
            }
            
        }

        public IReturnResult Result { get; set; }
        public IEnumerable<IMacrosTask> ScriptsContained { get; set; }
        public IList<IMacrosTask> DefaultChildsMethods { get; }
        public IList<NodeProperty> Properties { get; set; }
        public bool IsContainer { get { return false; } }
        public string LocalToken { get; set; }
        public IconImage IconImage { get { return new IconImage(new Bitmap(Appli.AssemblyDirectory + @"\icons\cog.png")); } }
        public IList<string> MethodsAllowedList { get; }
        public IList<string> MethodsNotAllowedList { get; }
        public IMacrosVars MacrosVariables { get; set; }
    }

MacrosFunction Example Code

public class TextTrim  : IMacrosFunction
    {


        //set the name of your function
        public string FunctionName { get; } = "Text Trim";
        //the category of your function
        public string FunctionCategory { get; } = "Text Processing";
        //the unique macros function code for your function
        public string FunctionCode { get; } = "Text.Trim";

        public TextTrim()
        {
            this.Properties = new List<NodeProperty>();
            this.Properties.Add(new NodeProperty("Text", ControlPropertyType.Text));
            this.Properties.Add(new NodeProperty("char", ControlPropertyType.Text));

        }
        public void ExecuteFunction(IMacrosHelper helper, Dictionary<string, string> Parameters)
        {
            char? chararcter = null;
            if(Parameters["char"] != String.Empty)
                    chararcter = Parameters["char"].ToChar();

            if (chararcter == null)
            {
                ReturnResult = Parameters["Text"].Trim();
            }
            else
            {
                ReturnResult = Parameters["Text"].Trim(chararcter.ToChar());
            }
           
        }

        //this is the return result of your macros function
        public string ReturnResult { get; set; }
        public IList<NodeProperty> Properties { get; }
        public string LocalToken { get; set; }
        public IMacrosVars MacrosVariables { get; set; }

Implementing You Addon Info & Addon Key:

Create a new class and implement the interface IAddonKey and all it's members.

public class PluginInfo : IAddonKey
    {
        //the unique key of your addon
        public string Key
        {
            get { return "addon key here"; }
        }
        //addon publisher url
        public string PublisherUrl
        {
            get { return "http://www.macrosengine.com/"; }
        }
        
        //addon version number
            public Version Version
        {
            get
            {
                return new Version("1.0");
            }
        }
        //addon license validation if the author has his own license validation.
        public bool ValidateLicense()
        {
            return true;
        }

    }