Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Editing Inkscape SVG files with Python?

30 views
Skip to first unread message

Steven D'Aprano

unread,
Sep 23, 2012, 6:53:43 PM9/23/12
to
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

Ben Finney

unread,
Sep 23, 2012, 9:02:55 PM9/23/12
to pytho...@python.org
Steven D'Aprano <steve+comp....@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

Matej Cepl

unread,
Sep 24, 2012, 2:06:02 AM9/24/12
to
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
0 new messages