This lesson is being piloted (Beta version)

DUNE HWDB Training: Generating bar/QR-code labels

This page describes how to configure paper & bar/QR label sizes as well as label positions within its sheet and generate label sheets using the Python HWDB Upload Tool.

label logo


With examples provided in this page, you will be able to:

Getting ready

Configuring custom_labels.py

THis is a sample custom_labels.py file. The contents of this file is merged with the default_labels.py file to produce a single label configuration. Open Configuring custom_labels.py with your editor. You will see the following 4 nodes under contents:

We’ll now go describe how to modify/use each of these 4 nodes.

page sizes:

Use this node to define other page sizes if you need more sizes than A4 (210.0,297.0) in mm and Letter (8.5, 11.0) in inches, which are already defined in default_labels.py By convention, we’ve been defining these in “portrait” orientation. If you wish to use a page in “landscape” orientation, you can specify that in “layouts”. You do not need to create a new page size definition for it.

"page sizes": {
        "A5": {
            "units": "mm",
            "size": (148.5, 210)
        }
    },

label templates:

Use this node to define the dimensions of label sheets. You may name these however you like, but the convention we’ve been using is <page size>-<columns>x<rows>-<brand name>.

"label templates": {
        "A4-6x11-Herma": {
            "description": "A4 (210×297 mm), 25.4×25.4 mm labels, 66 per sheet",
            "page size": "A4",
            "label size": (25.4, 25.4),
            "horizontal offsets": (16.1, 46.58, 77.06, 107.54, 138.02, 168.5),
            "vertical offsets": (
                     11.3,  36.7,  62.1,  87.5,
                    112.9, 138.3, 163.7, 189.1,
                    214.5 ,239.9, 265.3),
            "rounding": 2.0,
            "draw outline": False,
        }
    },


Already available label templates in default_labels.py:

There are some label templates already defined in default_labels.py for your immediate use.

layouts:

Use this node to define how you want the utility to print contents onto each label on a sheet defined in “templates”. You may define as many layouts as you wish for a given template.

"layouts": {
        "Herma 10107 A4-6x11 Layout": {
            "label template": "A4-6x11-Herma",
            "orientation": "portrait", # or portrait
            "debug": False,
            "elements": [
                {
                    "element type": "qr",
                    "alignment": "top-center",
                    "anchor": ["50%", "4%"],
                    "size": ["75%", "75%"],
                    "preserve aspect ratio": True,
                },
                {
                    "element type": "part id",
                    "alignment": "top-center",
                    "anchor": ["50%", "83%"],
                    "font size": "5%",
                    "preserve aspect ratio": True,
                },
                {
                    "element type": "part name",
                    "alignment": "top-center",
                    "anchor": ["50%", "90%"],
                    "font size": "5%",
                    "preserve aspect ratio": True,
                },
            ]
        },
    },


Already available layouts in default_labels.py:

There are some layouts already defined in default_labels.py for your immediate use. These layouts print QR-codes, along with the corresponding PIDs and the Component Type names.

label sets:

Label Sets define which layouts should be used with each part type. For instance, if you want to use two types of layouts, e.g., “Test Layout 1” and “Test Layout 2”, only for part type, “Z00100300001”, then you could have label set like the following.

 "label sets": {
        "Z00100300001": [
            "Test Layout 1", 
            "Test Layout 2",
        ],
    }

To use a set of layouts for all part types, use ‘default’ as the part name. (This will override the ‘default’ already set in default_labels.py). For instance:

 "label sets": {
        "default": [
            "Herma 10107 A4-6x11 Layout"
        ],
    }

Generating label sheets

Let’s generate a label sheet now. If you already setup your label sets as the following (as in the previous subsection):

 "label sets": {
        "default": [
            "Herma 10107 A4-6x11 Layout"
        ],
    }

then try the following command:

hwdb-labels D00599800007-00001

This creates labels.pdf locally. Open it with your PDF viewer. You should see a QR code drawn based on “Herma 10107 A4-6x11 Layout”.




Next, let’s try the following label sets.

 "label sets": {
        "Z00100300001": [
            "Test Layout 1", 
            "Test Layout 2",
            "Test Layout 3",
            "Test Layout 4",
            "Test Layout 5",
            "Test Layout 6",
        ],
    }

This label sets will use 6 different layouts for the Component Type ID = Z00100300001 only. We show the definitions of the 6 layouts below:

"layouts": {

        "Test Layout 1": {
            "label template": "Letter-2x3-Avery",
            "orientation": "portrait",
            "elements": [
                {
                    "element type": "qr",
                    "alignment": "top-left",
                    "anchor": ["10%", "10%"],
                    "size": ["40%", "30%"],
                    "preserve aspect ratio": True,
                },
                {
                    "element type": "bar",
                    "alignment": "top-left",
                    "anchor": ["60%", "10%"],
                    "size": ["30%", "30%"],
                    "preserve aspect ratio": True,
                },
                {
                    "element type": "part id",
                    "alignment": "top-left",
                    "anchor": ["10%", "55%"],
                    "font size": "5%",
                },
                {
                    "element type": "external id",
                    "alignment": "top-left",
                    "anchor": ["10%", "65%"],
                    "font size": "5%",
                },
                {
                    "element type": "part name",
                    "alignment": "top-left",
                    "anchor": ["10%", "75%"],
                    "font size": "5%",
                },
                {
                    "element type": "text",
                    "text": "Have a nice day!",
                    "alignment": "top-left",
                    "anchor": ["10%", "85%"],
                    "font size": "5%",
                },
            ],
        },

        "Test Layout 2": {
            "label template": "Letter-2x3-Avery",
            "debug": True,
            "elements": [
                {
                    "element type": "qr",
                    "alignment": "center",
                    "anchor": ["50%", "30%"],
                    "size": ["80%", "40%"],
                    "preserve aspect ratio": True,
                },
                {
                    "element type": "part id",
                    "alignment": "top-center",
                    "anchor": ["50%", "55%"],
                    "font size": "5%",
                },
                {
                    "element type": "part id",
                    "alignment": "center",
                    "anchor": ["50%", "65%"],
                    "font size": "5%",
                },
                {
                    "element type": "part id",
                    "alignment": "bottom-left",
                    "anchor": ["10%", "75%"],
                    "font size": "5%",
                },
                {
                    "element type": "part id",
                    "alignment": "bottom-right",
                    "anchor": ["90%", "85%"],
                    "font size": "5%",
                },
            ]
        },

        "Test Layout 3": {
            "label template": "Letter-2x3-Avery",
            "debug": True,
            "elements": [
                {
                    "element type": "qr",
                    "alignment": "bottom-right",
                    "anchor": ["90%", "50%"],
                    "size": ["80%", "40%"],
                    "preserve aspect ratio": True,
                },
            ]
        },

        "Test Layout 4": {
            "label template": "Letter-2x3-Avery",
            "debug": True,
            "elements": [
                {
                    "element type": "bar",
                    "alignment": "center-left",
                    "anchor": ["10%", "30%"],
                    "size": ["80%", "40%"],
                    "preserve aspect ratio": True,
                },
                {
                    "element type": "text",
                    "text": "Courier",
                    "alignment": "top-left",
                    "anchor": ["10%", "55%"],
                    "font size": "3.5%",
                    "font face": "Courier",
                },
                {
                    "element type": "text",
                    "text": "Courier-Bold",
                    "alignment": "top-left",
                    "anchor": ["50%", "55%"],
                    "font size": "3.5%",
                    "font face": "Courier-Bold",
                },
                {
                    "element type": "text",
                    "text": "Courier-Oblique",
                    "alignment": "top-left",
                    "anchor": ["10%", "63%"],
                    "font size": "3.5%",
                    "font face": "Courier-Oblique",
                },
                {
                    "element type": "text",
                    "text": "Courier-BoldOblique",
                    "alignment": "top-left",
                    "anchor": ["50%", "63%"],
                    "font size": "3.5%",
                    "font face": "Courier-BoldOblique",
                },
                {
                    "element type": "text",
                    "text": "Times-Roman",
                    "alignment": "top-left",
                    "anchor": ["10%", "71%"],
                    "font size": "3.5%",
                    "font face": "Times-Roman",
                },
                {
                    "element type": "text",
                    "text": "Times-Bold",
                    "alignment": "top-left",
                    "anchor": ["50%", "71%"],
                    "font size": "3.5%",
                    "font face": "Times-Bold",
                },
                {
                    "element type": "text",
                    "text": "Times-Italic",
                    "alignment": "top-left",
                    "anchor": ["10%", "79%"],
                    "font size": "3.5%",
                    "font face": "Times-Italic",
                },
                {
                    "element type": "text",
                    "text": "Times-BoldItalic",
                    "alignment": "top-left",
                    "anchor": ["50%", "79%"],
                    "font size": "3.5%",
                    "font face": "Times-BoldItalic",
                },
            ]
        },

        "Test Layout 5": {
            "label template": "Letter-2x3-Avery",
            "debug": True,
            "elements": [
                {
                    "element type": "qr",
                    "alignment": "center",
                    "anchor": ["30%", "50%"],
                    "size": ["80%", "40%"],
                    "preserve aspect ratio": True,
                    "rotate": 90,
                    
                },
                {
                    "element type": "text",
                    "font-size": "3.5%",
                    "anchor": ["50%", "10%"],
                    "text": "unrotated",
                },
                {
                    "element type": "text",
                    "font-size": "3.5%",
                    "anchor": ["50%", "30%"],
                    "text": "rotated 30 degrees",
                    "rotate": 30,
                },
            ]
        },

        "Test Layout 6": {
            "label template": "Letter-2x3-Avery",
            "orientation": "landscape",
            "debug": True,
            "elements": [
                {
                    "element type": "qr",
                    "alignment": "top-center",
                    "anchor": ["50%", "4%"],
                    "size": ["90%", "90%"],
                    "preserve aspect ratio": True,
                },
                {
                    "element type": "part id",
                    "alignment": "top-center",
                    "anchor": ["50%", "83%"],
                    "font size": "5%",
                    "preserve aspect ratio": True,
                },
                {
                    "element type": "part name",
                    "alignment": "top-center",
                    "anchor": ["50%", "90%"],
                    "font size": "5%",
                    "preserve aspect ratio": True,
                },
            ]
        },
    },

Now try the following command:

hwdb-labels Z00100300001-00001

The locally created labels.pdf show the following:

layout tests







Generating many labels at once:

In practice, you would be running a commend like this (as in the example given in Quick Start section);

hwdb-upload QE-docket.json

This will create a local directory with its directory name being a timesstamp (e.g., YYYYMMDDTHHMMSS). And inside of the newly created directory, ItemLabels.pdf will be created, which would look something like this:

QR tests