From bcddf5c48967ba125692b397e20a01ce1980ef51 Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Fri, 9 Apr 2021 10:36:29 +0200 Subject: [PATCH] fixed clones in perspective to work with InkScape 1.1dev/1.2dev --- .../fablabchemnitz/clonesperspective.py | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/extensions/fablabchemnitz/clonesperspective.py b/extensions/fablabchemnitz/clonesperspective.py index 5a883e84..4e4f258d 100644 --- a/extensions/fablabchemnitz/clonesperspective.py +++ b/extensions/fablabchemnitz/clonesperspective.py @@ -11,27 +11,24 @@ class clonesPerspectiveEffect(inkex.EffectExtension): self.arg_parser.add_argument('--ratio', type = float, default = 0.9, help = 'Ratio of size of nearest neighbor to first. Must be < 1') def effect(self): - svg = self.document.getroot() - num = int( self.options.num ) - ratio = float( self.options.ratio) - - if 1 != len(self.svg.selected) : - inkex.errormsg("Select exactly 1 thing. Group if necessary") + if len(self.svg.selected) != 1: + inkex.errormsg("Select exactly 1 thing. If necessary, group your items before.") sys.exit(1) - id = list(self.svg.selected.items())[0][0] - sel = self.svg.selected[id] - dic = sel.attrib + xpath = list(self.svg.selected.items())[0][0] + sel = self.svg.selected[xpath] + id = sel.get('id') + try : - tx = dic[inkex.addNS('transform-center-x','inkscape') ] - except KeyError : + tx = sel.attrib[inkex.addNS('transform-center-x','inkscape')] + except KeyError: tx = '0.' try : - ty = dic[inkex.addNS('transform-center-y','inkscape') ] - except KeyError : + ty = sel.attrib[inkex.addNS('transform-center-y','inkscape')] + except KeyError: ty = '0.' if float(tx) == 0. and float(ty) == 0. : - inkex.errormsg("Center of rotation at center of object") + inkex.errormsg("Center of rotation ist at the center of object. Please move the center first.") sys.exit(1) bbox = sel.bounding_box() @@ -47,10 +44,10 @@ class clonesPerspectiveEffect(inkex.EffectExtension): parent = sel.getparent() j = parent.index(sel) - for i in range(num) : - crat *= ratio - tx *= ratio - ty *= ratio + for i in range(self.options.num) : + crat *= self.options.ratio + tx *= self.options.ratio + ty *= self.options.ratio att = { "id" : self.svg.get_unique_id("clone" + id), inkex.addNS('href','xlink') : "#" + id,