OSP-BLOG

Open Source Publishing – Graphic Design Caravan

Inkscape plugins in Python

Tools · February 17th, 2008 ·

circles.png

Inkscape allows python scripts to be used as effects plugins. In a nutshell: you use the DOM to create / manipulate the structure of the SVG document and use CSS properties to style — so there’s quite some overlap with “regular” CGI & web programming.

This example (circles) is based on the example given on the Inkscape wiki. I started by making a simple Inkscape file (with a single circle), saving the file, then opened it in a text editor to view the “raw” XML structure of the SVG. I used this as a guide for what the code needed to produce.

circles.zip

Tags: · , ,

  • 7 Comments ↓

  • 1. Sammy

    Feb 18, 2008 at 8:33 pm

    Interesting. Could this open the door to the development of tools like Scriptographer ? (http://www.scriptographer.com/ – open source extensions for Illustrator)

  • 2. Femke

    Feb 20, 2008 at 1:47 pm

    And more! Look here for the kinds of extensions currently around; not only JavaScript (used by Scriptograper) but also Python, Perl and Bash…:
    http://wiki.inkscape.org/wiki/index.php/ExtensionsRepository
    (Warning: The Puff Effect is quite a bit different from the amazing aesthetics of most Scriptographer scripts ;-))

    To install this extension, I copied the files into /usr/share/inkscape/extensions and restarted Inkscape; after that a new menu-item ‘Python’ was added under ‘Effects’.

  • 3. nicolas

    Feb 20, 2008 at 9:49 pm

    Hello Sammy and Femke,

    Technically, scriptographer and the extensions of inkscape are not the same thing. Scriptographer is a java programme that ‘talks’ to the Illustrator functionalities. If Illustrator has a function that, for example, fills a shape with a color, scriptographer can trigger this ‘fill’ function without having to re-implement it.
    On the contrary, in Inkscape extensions, you have to write the functions yourself since the programme doesn’t answer to your script calls. It just passes the svg document to the script as input and tries to display it when the script has finished working on it. It is rather unfortunate since the most acrobatic parts of the inkscape code are difficult to re-implement. Therefore the pace of development of extensions may be a bit slower if you try to make ambitious things.

    However in the newest versions of inkscape, the developers offer two additional ways to script. One is from the outside of inkscape and ressembles a ‘slave’ mode. The other is to use an embedded console that allows you to inject python or perl code when the programme is open. I haven’t investigated these yet, but it seems that these new developments give the possibility to ‘talk’ to inkscape’s most interesting functionalities.

  • 4. Michael

    Feb 26, 2008 at 9:19 pm

    A useful resource: Aaron Spike’s webpages / examples of python extensions for Inkscape (but no pictures ;( ):
    http://www.ekips.org/comp/inkscape/

    In fact, it seems the examples I based my code on are from this site (in my “circles.inx” you still see traces of the “ekips” domain name — which I didn’t change).

  • 5. Stefan

    Jun 25, 2008 at 1:41 am

    If you look out for sth. like Scriptographer based on Python have a look at Nodebox (http://www.nodebox.net/).

  • 6. Nicolas

    Jun 25, 2008 at 3:18 pm

    hello Stefan,

    Nodebox looks awesome, indeed. By the way, Ricardo Lafuente is working on Shoebox, a rewrite of Nodebox that works on Linux using the Cairo backend. http://shoebox.sollec.org/

  • 7. Dave Crossland

    Sep 11, 2008 at 11:08 pm

    http://tinkerhouse.net/shoebot 🙂