Skip to content
Scott Pakin edited this page May 24, 2023 · 53 revisions

Simple Inkscape Scripting is an extension for the Inkscape vector-graphics application that facilitates scripting of graphical objects in Python. Once created, these objects can be manipulated in Inkscape's GUI like any other objects.

A quick reference guide summarizes all of the functions and variables that Simple Inkscape Scripting provides. The pages listed below organize Simple Inkscape Scripting's features by category and discuss each feature in depth.

Contents

Whetting your appetite

The following example fills the page with smiley faces of slightly varying size, color, and rotation. It showcases a number of Simple Inkscape Scripting features, including circles, paths, groups, styles, and transforms:

def make_smiley(fill_color='yellow'):
    'Return a smiley face of a given color.'
    head = circle((0, 0), 25, stroke='black', fill=fill_color)
    r_eye = circle((-9.2, -9.8), 5.4)
    l_eye = circle((9.2, -9.8), 5.4)
    mouth = path([Move(16.2, 4.2),
                  Curve(17.6, 10.3, 9.0, 19.4, 0.2, 19.4),
                  Curve(-9.0, 19.4, -17.8, 10.2, -16.2, 4.2),
                  Curve(-8.7, 9.4, 6.3, 9.4, 16.2, 4.2),
                  ZoneClose()])
    smiley = group([head, r_eye, l_eye, mouth])
    return smiley

# Draw a grid of slightly different smiley faces.
style(stroke='none', fill='black')
for y in range(30, int(canvas.height) - 30, 60):
    for x in range(30, int(canvas.width) - 30, 60):
        smiley = make_smiley(randcolor(range(225, 256), range(225, 256), [0]))
        smiley.rotate(uniform(-10, 10))
        smiley.scale(uniform(0.8, 1.1))
        smiley.translate((x, y))

The result looks like the following:

smileys

As you can imagine, drawing such repetitive images by hand would be extremely tedious.

Clone this wiki locally