inkscape-boolean-operations-in-extension.html
HTML document, Unicode text, UTF-8 text
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="UTF-8">
5
<title>
6
Using boolean operations in an Inkscape extension
7
</title>
8
<link rel="stylesheet" href="/static/style.css">
9
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10
</head>
11
<body>
12
<header>
13
<a href="#main" id="skip-link">Skip navigation</a>
14
<nav>
15
<ul>
16
<li><a href="/">Home</a></li>
17
<li><a href="/projects">Projects</a></li>
18
<li><a href="/index">Index</a></li>
19
<li><a href="/about">About</a></li>
20
<li><a href="https://roundabout-host.com/roundabout">Roundabout-host</a></li>
21
</ul>
22
<ul>
23
<li><a href="mailto:root@roundabout-host.com" id="mail-link">root@roundabout-host.com</a></li>
24
</ul>
25
</nav>
26
</header>
27
<main id="main">
28
29
<h1>Using boolean operations in an Inkscape extension</h1>
30
<div id="article-date">2025-11-22</div>
31
<p class="tags">
32
33
<a href="/index/inkscape.html" class="tag">inkscape</a>
34
35
<a href="/index/python.html" class="tag">python</a>
36
37
<a href="/index/tip.html" class="tag">tip</a>
38
39
</p>
40
41
<article class="content-area">
42
<p>I've wasted 3 days doing this, so I will at least publish my findings on the web
43
so you don't have to waste another 3 days. I wasn't able to find a good example
44
online and the docs are not well-made (not saying that they should be a
45
priority), so figuring it out does require some code research.
46
</p><p>The <code>inkex</code> module provides lots of things, but boolean operations aren't one of
47
them. Thus, you will have to call Inkscape yourself; luckily, <code>inkex</code> does
48
provide that.
49
</p><p>Even though they are listed as arguments, no special processing is done to the
50
values, which are still strings.
51
</p><p>I leave a minimal example:
52
</p><pre data-language="python">import inkex
53
import io
54
55
class UnionTwoPaths(inkex.EffectExtension):
56
def effect(self):
57
selected = list(self.svg.selection)
58
59
if len(selected) != 2:
60
inkex.errormsg("Select exactly two paths!")
61
return
62
63
# Make a string of the IDs
64
ids = ",".join([elem.get_id() for elem in selected])
65
66
# Call Inkscape to make a union
67
union_svg_bytes = inkex.command.inkscape_command(
68
self.document,
69
select=ids,
70
actions="path-union"
71
)
72
73
# Send the drawing back
74
self.document = inkex.load_svg(union_svg_bytes)
75
76
77
if __name__ == "__main__":
78
UnionTwoPaths().run()
79
</pre><pre data-language="xml"><?xml version="1.0" encoding="UTF-8"?>
80
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
81
<name>Union of two paths</name>
82
<id>org.inkscape.boolean.union_two_paths</id>
83
<effect>
84
<!-- Enable only on path objects (could use 'all' if preferred) -->
85
<object-type>path</object-type>
86
<effects-menu>
87
<submenu name="Generate from Path"/>
88
</effects-menu>
89
</effect>
90
<script>
91
<command reldir="extensions" interpreter="python">union_two_paths.py</command>
92
</script>
93
</inkscape-extension>
94
</pre>
95
</article>
96
97
</main>
98
<footer>
99
<p>Page generated on Saturday, 22 November 2025 at 16:22:48</p>
100
<p xmlns:cc="http://creativecommons.org/ns#" >This work is marked with <a href="https://creativecommons.org/publicdomain/zero/1.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC0 1.0 Universal</a> (🄍). No rights reserved.</p>
101
<p>Hosted at <a href="https://roundabout-host.com/roundabout">Roundabout-host</a> using the static site service, and generated with <a href="/projects/ampoule.html">Ampoule</a>.</p>
102
<a href="#">Back to top</a>
103
</footer>
104
</body>
105
</html>