Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #29870 > unrolled thread

Editing Inkscape SVG files with Python?

Started bySteven D'Aprano <steve+comp.lang.python@pearwood.info>
First post2012-09-23 22:53 +0000
Last post2012-09-24 08:06 +0200
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Editing Inkscape SVG files with Python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-23 22:53 +0000
    Re: Editing Inkscape SVG files with Python? Ben Finney <ben+python@benfinney.id.au> - 2012-09-24 11:02 +1000
    Re: Editing Inkscape SVG files with Python? Matej Cepl <mcepl@redhat.com> - 2012-09-24 08:06 +0200

#29870 — Editing Inkscape SVG files with Python?

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-09-23 22:53 +0000
SubjectEditing Inkscape SVG files with Python?
Message-ID<505f92f7$0$1612$c3e8da3$76491128@news.astraweb.com>
I have some SVG files generated with Inkscape containing many text blocks 
(over 100). I wish to programmatically modify those text blocks using 
Python. Is there a library I should be using, or any other guidelines or 
advice anyone can give me?

Googling for "python inkscape" comes up with too many hits for Inkscape's 
plugin system to be much help to me.


Thanks in advance.


-- 
Steven

[toc] | [next] | [standalone]


#29878

FromBen Finney <ben+python@benfinney.id.au>
Date2012-09-24 11:02 +1000
Message-ID<mailman.1172.1348448589.27098.python-list@python.org>
In reply to#29870
Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:

> I have some SVG files generated with Inkscape containing many text
> blocks (over 100). I wish to programmatically modify those text blocks
> using Python. Is there a library I should be using, or any other
> guidelines or advice anyone can give me?

My first step would be to use ‘lxml’ to manipulate an XML tree, since
that's what an SVG document contains.

Read the SVG file as a text string, de-serialise the text to an XML
tree. Match the nodes of interest using an XPath query, iterate over
them. Change the content of each node using Python text manipulation,
set the new value on the node. Re-serialise the tree to the SVG file.

-- 
 \       “I distrust those people who know so well what God wants them |
  `\    to do to their fellows, because it always coincides with their |
_o__)                      own desires.” —Susan Brownell Anthony, 1896 |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#29900

FromMatej Cepl <mcepl@redhat.com>
Date2012-09-24 08:06 +0200
Message-ID<k3ot2m$1oq0$1@ns.felk.cvut.cz>
In reply to#29870
On 24/09/12 00:53, Steven D'Aprano wrote:
> Googling for "python inkscape" comes up with too many hits for Inkscape's
> plugin system to be much help to me.

Aside from suggesting lxml, I would ask "So why not to follow the stream 
and create Inkscape plugin"? I have in similar situation created a 
plugin (https://gitorious.org/inkscape-ungroup-deep/) and I have to say 
it wasn't that difficult and results are pretty satisfactory.

Matěj

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web