Scripting Paint by Zaweba with C# and the Script Console
Write C# scripts in Paint by Zaweba: run .csx files, test code in the Script Console and drive documents, layers, filters, actions, saving and printing.

Actions record what you do with the mouse. Scripts let you describe what should happen with code, which opens up jobs that recording can't handle. Paint by Zaweba has a File > Scripts menu with Run Script, a Script Console and a scripts folder of .csx files. The scripts are C#, compiled with Roslyn, and they can work with the document, layers, selection, filters, actions, and opening, saving and printing.
Why C#
C# is a widely used, well documented language, and .csx is its scripting form: a single file without the ceremony of a full project. Roslyn is the C# compiler, so scripts are compiled rather than interpreted, and run at the speed of normal code. If you have written C# before, you will feel at home. If you haven't, it is a friendly language to learn, with plenty of free tutorials.
The Script Console
The Script Console is the place to experiment. Type some code and press Ctrl+Enter to run it against the current document. It is ideal for trying a single line, checking what a layer is called, or working out a loop before saving it as a script.
A good way to learn is to start small in the console: read the document's size, list its layers, change one layer's opacity. Once each piece works, put them together in a .csx file.
Run Script and the scripts folder
Run Script opens and runs a .csx file. The scripts folder keeps your .csx files together in one known place, so your own tools are always close at hand. Share the files with colleagues, keep them in version control, or build up a personal toolkit over time.
What scripts can do
Because scripts reach the document, layers, selection, filters, actions, and open, save and print, they can do almost anything you would do by hand, plus things that are tedious by hand. A few ideas:
Process files with logic an action can't express, for example choosing a crop depending on the image's proportions, or skipping images that are already small enough. Build a document from data, placing images and text from a list. Rename and reorder layers in a large file according to rules. Run several actions in a sequence decided by what the image contains. Export the same design to a set of sizes and formats with names generated from a template.
Scripts can also be triggered by the Script Events Manager on start, new, open, save, export or close, so a script can run every time you save without you remembering to call it.
Writing scripts safely
Work on copies until a script is proven. Code that saves can overwrite files just as quickly as it can create them. Write output to a new folder while you're testing.
Keep scripts readable. A comment at the top explaining what a script is for saves time when you come back to it months later.
Combine with actions. If a sequence of steps is easy to record, record it as an action and call that action from the script, rather than rewriting every step in code.
The top of the automation ladder
Scripting sits at the top of the automation ladder in Paint by Zaweba: actions for recorded steps, batches and Droplets for folders, Script Events for automatic triggers, and scripts for anything that needs logic. It all runs locally, with no online service involved, so your images and your code stay on your PC.