fixed clones in perspective to work with InkScape 1.1dev/1.2dev

This commit is contained in:
Mario Voigt 2021-04-09 10:36:29 +02:00
parent 707341e04d
commit bcddf5c489

View File

@ -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') 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): def effect(self):
svg = self.document.getroot() if len(self.svg.selected) != 1:
num = int( self.options.num ) inkex.errormsg("Select exactly 1 thing. If necessary, group your items before.")
ratio = float( self.options.ratio)
if 1 != len(self.svg.selected) :
inkex.errormsg("Select exactly 1 thing. Group if necessary")
sys.exit(1) sys.exit(1)
id = list(self.svg.selected.items())[0][0] xpath = list(self.svg.selected.items())[0][0]
sel = self.svg.selected[id] sel = self.svg.selected[xpath]
dic = sel.attrib id = sel.get('id')
try : try :
tx = dic[inkex.addNS('transform-center-x','inkscape') ] tx = sel.attrib[inkex.addNS('transform-center-x','inkscape')]
except KeyError: except KeyError:
tx = '0.' tx = '0.'
try : try :
ty = dic[inkex.addNS('transform-center-y','inkscape') ] ty = sel.attrib[inkex.addNS('transform-center-y','inkscape')]
except KeyError: except KeyError:
ty = '0.' ty = '0.'
if float(tx) == 0. and float(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) sys.exit(1)
bbox = sel.bounding_box() bbox = sel.bounding_box()
@ -47,10 +44,10 @@ class clonesPerspectiveEffect(inkex.EffectExtension):
parent = sel.getparent() parent = sel.getparent()
j = parent.index(sel) j = parent.index(sel)
for i in range(num) : for i in range(self.options.num) :
crat *= ratio crat *= self.options.ratio
tx *= ratio tx *= self.options.ratio
ty *= ratio ty *= self.options.ratio
att = { att = {
"id" : self.svg.get_unique_id("clone" + id), "id" : self.svg.get_unique_id("clone" + id),
inkex.addNS('href','xlink') : "#" + id, inkex.addNS('href','xlink') : "#" + id,