This repository has been archived by the owner on Mar 22, 2019. It is now read-only.
forked from ryanlerch/inkscape-extension-multiple-difference
-
Notifications
You must be signed in to change notification settings - Fork 1
/
multipledifference.py
76 lines (64 loc) · 2.71 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
# Inkscape Multi-Bool extension for Inkscape 0.91
# Copyright (C) 2014 Ryan Lerch (multiple difference)
# 2016 Maren Hachmann <marenhachmannATyahoo.com> (refactoring, extend to multibool)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
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
from lxml import etree
from shutil import copy2
class MultipleDifference(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
def effect(self):
file = self.args[-1]
tempfile = os.path.splitext(file)[0] + "-multidiff.svg"
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()
copy2(file, tempfile)
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 "
commandstring += "--verb=FileSave --verb=FileQuit "
p = Popen(commandstring+tempfile, shell=True, stdout=PIPE, stderr=PIPE)
err = p.stderr
f = p.communicate()[0]
err.close()
self.document = etree.parse(tempfile)
if __name__ == '__main__':
e = MultipleDifference()
e.affect()