-
Notifications
You must be signed in to change notification settings - Fork 33
Home
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.
- Running (Simple Inkscape Scripting invocation)
- Shape construction (circles, rectangles, text, paths, …)
- Common arguments (transformations, connector avoidance, clipping paths, masks, and styles)
- Changing defaults (applying the same transformations and styles to multiple shapes)
- Object collections (groups and layers)
- Copying objects (linked and unlinked replicas of a shape)
- Path operations (converting shapes to paths and manipulating them)
- Effects (gradients, markers, filters, and live path effects)
- Modifying existing objects (altering objects that may or may not have been created by Simple Inkscape Scripting)
- Document layout (querying/modifying the canvas size and coordinate system and creating/accessing pages)
- Animation (changing object properties over time)
- Metadata (reading and writing document metadata such as title, creator, description, and license)
- Other features (miscellaneous Simple Inkscape Scripting features)
- Advanced usage (low-level SVG access)
- Derived extensions (giving your script its own Inkscape menu item)
- List of examples
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:
As you can imagine, drawing such repetitive images by hand would be extremely tedious.