If I manually edit the SVG I can point the a xlink:href to anything, e.g. text123 and it works fine. The extension creates the Use, I can view the attribs, but it just won't add to the document if it is not a path.
I found clones_in_perspective extension in the Mightyscape collection, which adds clones in a different way. I've stripped the code down to this, but it also does not work on anything that isn't a single path. But for some reason the extension itself works fine on text, shapes etc
Thanks for the reply, it helped me narrow down the issue. I was just making a stupid mistake in my code. I forgot to remove a inkex.abortextension that was being called if the selection wasn't a path further down....
Hi, I'm trying to clone a selected object, but it only seems to work on single paths, not on groups, rectangles, text etc.
Minimum working example:
If I manually edit the SVG I can point the a xlink:href to anything, e.g. text123 and it works fine. The extension creates the Use, I can view the attribs, but it just won't add to the document if it is not a path.
I found clones_in_perspective extension in the Mightyscape collection, which adds clones in a different way. I've stripped the code down to this, but it also does not work on anything that isn't a single path. But for some reason the extension itself works fine on text, shapes etc
I'm not sure if this is a bug, or something I'm missing. Inkscape 1.3
It should be as simple as this:
import inkex
from inkex import Use
def clone_element(self, element):
new_clone = Use()
new_clone.set('xlink:href', f'#{element.get_id()}')
self.svg.get_current_layer().append(new_clone)
class MakeClones(inkex.EffectExtension):
def add_arguments(self, pars):
pass
def effect(self):
selection_list = self.svg.selected
if len(selection_list) < 1:
return
for item in selection_list:
clone_element(self, item)
if __name__ == '__main__':
MakeClones().run()
Thanks for the reply, it helped me narrow down the issue. I was just making a stupid mistake in my code. I forgot to remove a inkex.abortextension that was being called if the selection wasn't a path further down....
I think this can be simplified to:
Old thread I know, but it comes up when searching for help with cloning objects.