1

I'd like to draw a few simple objects in Inkscape (lines, circles, rectangles), group them, move them around, scale, rotate, make copies, etc. and then I need something which will let me load the SVG into Python and iterate over all these shapes, getting the relevant attributes (for circles: centre and radius; for lines: the two end-points; etc.).

I've installed and tried svg-utils, pysvg, svgfig and read about inkex, and while all of these seem to allow me to iterate through the XML structure, with varying degrees of awkwardness, as far as I can see none of them apply the transforms to the elements. So, if I draw a line from (0,0) to (1,1), group it, move it to (100,100), then its XML tag is still going to say (0,0) to (1,1), but its real position is computed by applying the transform in its containing group, to these end-points.

I don't want to write all this transform-application code myself, because that would be re-inventing the bicycle. But I need help finding a convenient existing bicycle...

One likely useful route is to find an exporter into a simple format, which would already have had to solve all these problems. Here is an example I found: http://en.wikipedia.org/wiki/SK1_%28program%29#Supported_formats

But which of the export formats listed there is likely to be the simplest?

Evgeni Sergeev
  • 22,495
  • 17
  • 107
  • 124
  • Can you post an example of the svg you'd like to create, as well as what your desired output is? – miah Aug 15 '13 at 14:37
  • 1
    You could use [Inkscape to load and save the SVG in optimized mode](http://stackoverflow.com/a/10941779/1599111), therefore applying the transformations. – Lukas Graf Aug 15 '13 at 15:31
  • @miah Input is described sufficiently. Output would be like this: `{'circles' : [((0,0), 1), ((10,10), 1)], 'lines' : [((0,0), (10,10)), ((1,1), (2,2))]}`. All objects which are not circles and lines are ignored. For circles, the description is centre+radius, for lines it's the two end-points. – Evgeni Sergeev Aug 15 '13 at 23:00
  • @LukasGraf That's an interesting idea. The way they get things out of groups, no matter how deep those are, is by cutting then pasting. – Evgeni Sergeev Aug 15 '13 at 23:02

0 Answers0