Hi all,

Given a selected object (e.g. firstObject = self.selected[self.options.ids[0]]) in a Python extension, how can I duplicate it? I've checked a couple of code snippets (e.g. pathscatter.py as well as some online content) and stumbled upon copy.deepcopy(...) and append() for layers, but I don't have it working properly yet.

Usually, I add a new object (e.g. a path) using

newObject = inkex.etree.SubElement(self.current_layer, inkex.addNS('path','svg'), pathAttribs),

where pathAttribs has been defined before. Can I add the duplicated object in a similar way? When I substitute 'pathAttribs' with 'firstObject' or a deepcopy() of it, I get the following FutureWarning —

FutureWarning: The behavior of this method will change in future versions. Use specific 'len(elem)' or 'elem is not None' test instead.
  newObject = inkex.etree.SubElement(self.current_layer, inkex.addNS('path','svg'), firstObject)

As an exercise I'm trying to write an extension that generates a circular array of a selected (path) object. The approach could be to first duplicate the object and subsequently transform it (i.e. rotate and possibly translate) using simpletransform.composeTransform () and simpletransform.applyTransformToPath().

As a follow-up question, is it possible to clone an object from within a Python extension? With 'clone' I mean the operation that's available in Inkscape through Edit → Clone → Create Clone.

Thanks! Best,
Pieter