Introduction

We have compiled a series of commonly used code recipes in Draft into this cookbook. First off, if you aren’t familiar, a code recipe is a snippet of code that captures a common case. The goal is so that you don’t have to remember exactly how to do something, like how to setup a certain type of video encoder, and instead have a place to quickly refer to when you need to cook something up!

You can use this cookbook both as way to learn new techniques and functions in Draft, as well as a handy reference whenever you need it. While reading it from start to finish would be helpful, the intention is that you use it by jumping around the table of contents based on what you are interested in.

We will be adding new recipes in the future and if you would like to suggest new additions. please post on our forums.

These recipies make the assumption that you are familiar with the Python programming language, so we won’t be taking too many pains to explain the syntatic details of the recipes. The discussions will focus primarily on what Draft is doing and what other options might be available to you.

Conventions Used

Here are the conventions we use throughout this cookbook.

Each recipe is in response to a given Problem. This can be something fairly simple like Creating an Image to something much more complex like Compositing images using Anchors.

The Solution is the code snippet that solves the stated problem. The recipe will be formatted with Python highlights to make it easier to look at. Copy the recipe code into your own scripts to use it.

Finally, each recipe is accompanied by a Discussion of the solution. The discussion is not required reading, but often includes further details and offers helpful hints when needing to solve more complex problems. Where appropriate, sometimes a See Also section is included to link to other relevant recipes or documentation.

When we refer to code within the discussion text, quoted code is formatted like this to help make it stand out. When we include code lines, they will appear on their own line and be in a different font.

For example, the Draft library is imported into a Python script in the standard manner:

import Draft

The module Draft contains several important objects such as Draft.Image.