-
Notifications
You must be signed in to change notification settings - Fork 6
/
multipledifference.py
50 lines (41 loc) · 1.52 KB
/
multipledifference.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
"""
This extension takes a selection of paths, and applies a difference
between the top shape in the z-order, and each of the shapes underneath.
"""
import inkex, os, csv, math
from subprocess import Popen, PIPE
class MultipleDifference(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
def effect(self):
file = self.args[-1]
p = Popen('inkscape --query-all '+file, shell=True, stdout=PIPE, stderr=PIPE)
err = p.stderr
f = p.communicate()[0]
lines=csv.reader(f.split(os.linesep))
err.close()
documentobjects = []
for line in lines:
if len(line) > 0:
documentobjects.append(line[0])
commandstring="inkscape "
first = True
toppath=""
selecteditems = self.selected
documentobjects.reverse()
if len(selecteditems) > 1:
for o in documentobjects:
if o in selecteditems:
if first:
toppath=o
first = False
else:
commandstring = commandstring + "--select="+toppath+" --verb=EditDuplicate --select="+o+" --verb=SelectionDiff --verb=EditDeselect "
p = Popen(commandstring+file, shell=True, stdout=PIPE, stderr=PIPE)
err = p.stderr
f = p.communicate()[0]
err.close()
if __name__ == '__main__':
e = MultipleDifference()
e.affect()