Automate everything

User Tools

Site Tools


Translations of this page:


Usage of C # Macros

Please note! This feature is for advanced users only.
From 4.3 to ZennoPoster an opportunity to use a new type of action “C # code.” This action allows you to write pieces of code in C #. You have access to a running project using variable 'project', access to the instance through a variable 'instance', there is also an additional class Macros, there are simple commands for word processing and operations with file system. To get more information about available functions, read documentation

You can use C # macros for:

* Replacement of macros from ZennoPoster 3. Now even sub-macros are legible and understandable
* Compact architecture of project, when you can group few unimportant actions together in one
* Extend the functionality of the program. Quite often we are asked to create some functions that will be useful for a very limited number of customers. You can use C # macros now for all your new needs without changing code of ZennoPoster and awaiting for the new build

How to add C # macro

Simply drag “C # code” in the project, write code and configure the output variables.

My first macro

By tradition, we will write a macro that returns “Hello wolrd!”

return "Hello wolrd!";

Debug result

Useful macro

For example do you have a file with the keywords and you want to take 10 random keywords from it , combine them, and save to variable. Lets say the path to the file with keywords stored in the variable pathToKeyWordFile

/ / Read the file path from a variable
var path = project.Variables ["pathToKeyWordFile"]. Value;
/ / Read 10 random lines from a file
var lines = new List <string> ();
for (int i = 0; i <10; i + +) {
lines.Add (Macros.FileSystem.FileGetLine (path, "random"));
/ / Return the keywords with ";" as separator
return string.Join (";", lines);

Advantages of C # macros

* Speed: macros are compiled before start of the project, not parsed every time comparing to normal operations.
* Less memory usage for typical actions.
* You can connect a third-party modules from GAC, to work with databases for example.

Limitations of C # macros

The only one restriction: you can not write ZennoPoster macros directly in code, you can access variables, lists, tables, and profiles through a variable 'project' and access to the instance - through a variable 'instance'.

Sample of C# use

en/zennoposter/using-csharp-macro.txt · Last modified: 2021/01/23 21:08 by sergodjan