<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.inkscape.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rubikcube</id>
	<title>Inkscape Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.inkscape.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rubikcube"/>
	<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/Special:Contributions/Rubikcube"/>
	<updated>2026-04-25T12:21:06Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PowerStroke&amp;diff=35524</id>
		<title>PowerStroke</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PowerStroke&amp;diff=35524"/>
		<updated>2008-09-03T17:26:47Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: added comment -&amp;gt; synfig&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Power stroke =&lt;br /&gt;
&lt;br /&gt;
The proposed power stroke LPE is as follow:&lt;br /&gt;
&lt;br /&gt;
[[Image:Power-stroke-1.png]]&lt;br /&gt;
&lt;br /&gt;
== Functionality ==&lt;br /&gt;
&lt;br /&gt;
This LPE allows a modulated stroke from manually entered values.&lt;br /&gt;
&lt;br /&gt;
Further development could allow direct width reading from a pressure-enabled device.&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
&lt;br /&gt;
The user simply creates the line, it might for example be based on an outline.&lt;br /&gt;
&lt;br /&gt;
Then the user applies the LPE to his shape, it overrides the normal stroke rendering and allows custom line width at different nodes of the path.&lt;br /&gt;
&lt;br /&gt;
Only the stroke-width property of the path is overridden, the rest of the stroke properties keep working as usual, when relevant.&lt;br /&gt;
&lt;br /&gt;
== GUI ==&lt;br /&gt;
&lt;br /&gt;
Se image above. User selects a nodes or a set of nodes and affects values to those. When a node is selected, you can see what its value is by the change in values in the number entry or by the state of the push button.&lt;br /&gt;
&lt;br /&gt;
Additionally, hovering over a node could show the value of a node. Graphical feedback could even possibly set different icons for nodes that are set and others that are interpolated.&lt;br /&gt;
&lt;br /&gt;
Perhaps Alt+drag a node to change the thickness?&lt;br /&gt;
&lt;br /&gt;
A combination of a metakey and the scroll wheel would be intuitive as well (with status bar message stating you can do that, of course). -- [[jegHegy]]&lt;br /&gt;
&lt;br /&gt;
= Comments =&lt;br /&gt;
&lt;br /&gt;
== By JohanE ==&lt;br /&gt;
This is very well doable, but would require a new &amp;quot;Nodepath&amp;quot; implementation that enables writing special values (preferably a struct) per node. There is already something like this, the &amp;quot;nodetypes&amp;quot; attribute, but it is too restrictive. Expanding this would enable this effect, and opens up many other possibilities. Nice idea !&lt;br /&gt;
&lt;br /&gt;
== By Pajarico ==&lt;br /&gt;
I'm thinking this tool could allow the user to copy a path or an object or group of objects to any node in a path. Which is similar to what you're proposing, only this doesn't use interpolation between adjacent nodes, it just places an element on a specific node (or nodes if you have several selected).&lt;br /&gt;
&lt;br /&gt;
I'm not sure if it is better to open a separate blueprint or not. --Pajarico, [[User:Pajarico|Pajarico]] 22:36, 21 June 2008 (UTC)&lt;br /&gt;
&lt;br /&gt;
== By rubikcube ==&lt;br /&gt;
You might want to have a look at how [http://www.synfig.org synfig] handles varying width for paths.  Paths are called &amp;quot;Blines&amp;quot; there, the relevant feature is explained shortly at the bottom of [http://synfig.org/Creating_Shapes one of its manual pages]. --[[User:Rubikcube|Rubikcube]] 17:26, 3 September 2008 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33894</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33894"/>
		<updated>2008-08-07T21:51:45Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: Link to python documentation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads an SVG file from standard input, transforms it somehow and prints it to the standart output.  Usually Inkscape sits on both ends, providing the file with some parameters as input first and finally reading the output, which is then used for further work.&lt;br /&gt;
[[Image:Effect_flow.svg|thumb|right|400px]]&lt;br /&gt;
&lt;br /&gt;
We will write a simple effect extension script in [http://docs.python.org Python] that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
''This script won't work with the current version of inkscape, it might still help as a useful guide how to create your own scripts though.  Especially the methods to access the xml structure have changed, please refer to the [http://codespeak.net/lxml/ lxml] documentation.''&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create a file ''hello_world.py'' and make it executable with the Python interpreter with the well-known directive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import the ''inkex.py'' file with the ''Effect'' base class that will do most of the work for us and the ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare a ''HelloWordEffect'' class that inherits from ''Effect'' and write a constructor where the base class is initialized and script options for the option parser are defined:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The complete documentation for the ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use the ''add_option'' method which has as first argument a short option name, as second argument a long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with the default values specified using the ''.inx'' file for this extension which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide the desired effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you can imagine we just stored the ''--what'' option value to the ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will have to work with the XML representation of the SVG document that we can access via ''Effect'''s ''self.document'' attribute.&lt;br /&gt;
It is of lxml's '' _ElementTree'' class type.  Complete documentation for the lxml package lxml can be found at http://codespeak.net/lxml/.&lt;br /&gt;
&lt;br /&gt;
First we get SVG document's ''svg'' element and its dimensions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getroot()&lt;br /&gt;
        # or alternatively&lt;br /&gt;
        # svg = self.document.xpath('//svg:svg',namespaces=inkex.NSS)[0]&lt;br /&gt;
&lt;br /&gt;
        # Again, there are two ways to get the attibutes:&lt;br /&gt;
        width  = inkex.unittouu(svg.get('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.attrib['height'])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The ''xpath'' function returns a list of all matching elements so we just use the first one of them.&lt;br /&gt;
&lt;br /&gt;
We now create an SVG group element ('' 'g' '') and &amp;quot;mark&amp;quot; it as a layer using Inkscape' SVG extensions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = inkex.etree.SubElement(svg, 'g')&lt;br /&gt;
        layer.set(inkex.addNS('label', 'inkscape'), 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This creates ''inkscape:label'' and ''inkscape:groupmode'' attributes, which will only be read by Inkscape or compatible applications.  To all other viewers, this new element looks just like a plain SVG group.&lt;br /&gt;
&lt;br /&gt;
Now we create an SVG text element with a text value containing the &amp;quot;Hello World&amp;quot; string:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = inkex.etree.Element(inkex.addNS('text','svg'))&lt;br /&gt;
        text.text = 'Hello %s!' % (what)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the position of the text to the center of SVG document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.set('x', str(width / 2))&lt;br /&gt;
        text.set('y', str(height / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to center the text on its position we need to define the CSS style of the SVG ''text'' element. Actually we use the ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.set('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we connect all created elements together and put them into the SVG document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer.append(text)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class that inherited from the original effect extension so we have to create an instance of it and execute it in the main control flow:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules to the ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory.  On Linux you will probably have to make the python script executable first if you haven't done this yet.  This is usually done by the usual command (or in your preferred file manager):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ chmod a+x hello_world.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions')&lt;br /&gt;
&lt;br /&gt;
# We will use the inkex module with the predefined Effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
# The simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Example Inkscape effect extension.&lt;br /&gt;
    Creates a new layer with a &amp;quot;Hello World!&amp;quot; text centered in the middle of the document.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Constructor.&lt;br /&gt;
        Defines the &amp;quot;--what&amp;quot; option of a script.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # Call the base class constructor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Effect behaviour.&lt;br /&gt;
        Overrides base class' method and inserts &amp;quot;Hello World&amp;quot; text into SVG document.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # Get script's &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getroot()&lt;br /&gt;
        # or alternatively&lt;br /&gt;
        # svg = self.document.xpath('//svg:svg',namespaces=inkex.NSS)[0]&lt;br /&gt;
&lt;br /&gt;
        # Again, there are two ways to get the attibutes:&lt;br /&gt;
        width  = inkex.unittouu(svg.get('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.attrib['height'])&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = inkex.etree.SubElement(svg, 'g')&lt;br /&gt;
        layer.set(inkex.addNS('label', 'inkscape'), 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = inkex.etree.Element(inkex.addNS('text','svg'))&lt;br /&gt;
        text.text = 'Hello %s!' % (what)&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.set('x', str(width / 2))&lt;br /&gt;
        text.set('y', str(height / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.set('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        layer.append(text)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Last edited by --[[User:Rubikcube|Rubikcube]] 21:18, 7 August 2008 (UTC), based on a version by&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=Talk:PythonEffectTutorial&amp;diff=33884</id>
		<title>Talk:PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=Talk:PythonEffectTutorial&amp;diff=33884"/>
		<updated>2008-08-07T21:21:16Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: should work now&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Current issues==&lt;br /&gt;
* None left that I know of, it should work now with a current installation. --[[User:Rubikcube|Rubikcube]] 21:21, 7 August 2008 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33874</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33874"/>
		<updated>2008-08-07T21:19:53Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: /* Complete Source Code */ adaped docstrings&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads an SVG file from standard input, transforms it somehow and prints it to the standart output.  Usually Inkscape sits on both ends, providing the file with some parameters as input first and finally reading the output, which is then used for further work.&lt;br /&gt;
[[Image:Effect_flow.svg|thumb|right|400px]]&lt;br /&gt;
&lt;br /&gt;
We will write a simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
''This script won't work with the current version of inkscape, it might still help as a useful guide how to create your own scripts though.  Especially the methods to access the xml structure have changed, please refer to the [http://codespeak.net/lxml/ lxml] documentation.''&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create a file ''hello_world.py'' and make it executable with the Python interpreter with the well-known directive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import the ''inkex.py'' file with the ''Effect'' base class that will do most of the work for us and the ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare a ''HelloWordEffect'' class that inherits from ''Effect'' and write a constructor where the base class is initialized and script options for the option parser are defined:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The complete documentation for the ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use the ''add_option'' method which has as first argument a short option name, as second argument a long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with the default values specified using the ''.inx'' file for this extension which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide the desired effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you can imagine we just stored the ''--what'' option value to the ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will have to work with the XML representation of the SVG document that we can access via ''Effect'''s ''self.document'' attribute.&lt;br /&gt;
It is of lxml's '' _ElementTree'' class type.  Complete documentation for the lxml package lxml can be found at http://codespeak.net/lxml/.&lt;br /&gt;
&lt;br /&gt;
First we get SVG document's ''svg'' element and its dimensions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getroot()&lt;br /&gt;
        # or alternatively&lt;br /&gt;
        # svg = self.document.xpath('//svg:svg',namespaces=inkex.NSS)[0]&lt;br /&gt;
&lt;br /&gt;
        # Again, there are two ways to get the attibutes:&lt;br /&gt;
        width  = inkex.unittouu(svg.get('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.attrib['height'])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The ''xpath'' function returns a list of all matching elements so we just use the first one of them.&lt;br /&gt;
&lt;br /&gt;
We now create an SVG group element ('' 'g' '') and &amp;quot;mark&amp;quot; it as a layer using Inkscape' SVG extensions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = inkex.etree.SubElement(svg, 'g')&lt;br /&gt;
        layer.set(inkex.addNS('label', 'inkscape'), 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This creates ''inkscape:label'' and ''inkscape:groupmode'' attributes, which will only be read by Inkscape or compatible applications.  To all other viewers, this new element looks just like a plain SVG group.&lt;br /&gt;
&lt;br /&gt;
Now we create an SVG text element with a text value containing the &amp;quot;Hello World&amp;quot; string:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = inkex.etree.Element(inkex.addNS('text','svg'))&lt;br /&gt;
        text.text = 'Hello %s!' % (what)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the position of the text to the center of SVG document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.set('x', str(width / 2))&lt;br /&gt;
        text.set('y', str(height / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to center the text on its position we need to define the CSS style of the SVG ''text'' element. Actually we use the ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.set('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we connect all created elements together and put them into the SVG document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer.append(text)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class that inherited from the original effect extension so we have to create an instance of it and execute it in the main control flow:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules to the ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory.  On Linux you will probably have to make the python script executable first if you haven't done this yet.  This is usually done by the usual command (or in your preferred file manager):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ chmod a+x hello_world.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions')&lt;br /&gt;
&lt;br /&gt;
# We will use the inkex module with the predefined Effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
# The simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Example Inkscape effect extension.&lt;br /&gt;
    Creates a new layer with a &amp;quot;Hello World!&amp;quot; text centered in the middle of the document.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Constructor.&lt;br /&gt;
        Defines the &amp;quot;--what&amp;quot; option of a script.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # Call the base class constructor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Effect behaviour.&lt;br /&gt;
        Overrides base class' method and inserts &amp;quot;Hello World&amp;quot; text into SVG document.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # Get script's &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getroot()&lt;br /&gt;
        # or alternatively&lt;br /&gt;
        # svg = self.document.xpath('//svg:svg',namespaces=inkex.NSS)[0]&lt;br /&gt;
&lt;br /&gt;
        # Again, there are two ways to get the attibutes:&lt;br /&gt;
        width  = inkex.unittouu(svg.get('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.attrib['height'])&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = inkex.etree.SubElement(svg, 'g')&lt;br /&gt;
        layer.set(inkex.addNS('label', 'inkscape'), 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = inkex.etree.Element(inkex.addNS('text','svg'))&lt;br /&gt;
        text.text = 'Hello %s!' % (what)&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.set('x', str(width / 2))&lt;br /&gt;
        text.set('y', str(height / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.set('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        layer.append(text)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Last edited by --[[User:Rubikcube|Rubikcube]] 21:18, 7 August 2008 (UTC), based on a version by&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33864</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33864"/>
		<updated>2008-08-07T21:18:06Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: /* Complete Source Code */ changed complete source code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads an SVG file from standard input, transforms it somehow and prints it to the standart output.  Usually Inkscape sits on both ends, providing the file with some parameters as input first and finally reading the output, which is then used for further work.&lt;br /&gt;
[[Image:Effect_flow.svg|thumb|right|400px]]&lt;br /&gt;
&lt;br /&gt;
We will write a simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
''This script won't work with the current version of inkscape, it might still help as a useful guide how to create your own scripts though.  Especially the methods to access the xml structure have changed, please refer to the [http://codespeak.net/lxml/ lxml] documentation.''&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create a file ''hello_world.py'' and make it executable with the Python interpreter with the well-known directive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import the ''inkex.py'' file with the ''Effect'' base class that will do most of the work for us and the ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare a ''HelloWordEffect'' class that inherits from ''Effect'' and write a constructor where the base class is initialized and script options for the option parser are defined:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The complete documentation for the ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use the ''add_option'' method which has as first argument a short option name, as second argument a long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with the default values specified using the ''.inx'' file for this extension which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide the desired effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you can imagine we just stored the ''--what'' option value to the ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will have to work with the XML representation of the SVG document that we can access via ''Effect'''s ''self.document'' attribute.&lt;br /&gt;
It is of lxml's '' _ElementTree'' class type.  Complete documentation for the lxml package lxml can be found at http://codespeak.net/lxml/.&lt;br /&gt;
&lt;br /&gt;
First we get SVG document's ''svg'' element and its dimensions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getroot()&lt;br /&gt;
        # or alternatively&lt;br /&gt;
        # svg = self.document.xpath('//svg:svg',namespaces=inkex.NSS)[0]&lt;br /&gt;
&lt;br /&gt;
        # Again, there are two ways to get the attibutes:&lt;br /&gt;
        width  = inkex.unittouu(svg.get('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.attrib['height'])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The ''xpath'' function returns a list of all matching elements so we just use the first one of them.&lt;br /&gt;
&lt;br /&gt;
We now create an SVG group element ('' 'g' '') and &amp;quot;mark&amp;quot; it as a layer using Inkscape' SVG extensions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = inkex.etree.SubElement(svg, 'g')&lt;br /&gt;
        layer.set(inkex.addNS('label', 'inkscape'), 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This creates ''inkscape:label'' and ''inkscape:groupmode'' attributes, which will only be read by Inkscape or compatible applications.  To all other viewers, this new element looks just like a plain SVG group.&lt;br /&gt;
&lt;br /&gt;
Now we create an SVG text element with a text value containing the &amp;quot;Hello World&amp;quot; string:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = inkex.etree.Element(inkex.addNS('text','svg'))&lt;br /&gt;
        text.text = 'Hello %s!' % (what)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the position of the text to the center of SVG document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.set('x', str(width / 2))&lt;br /&gt;
        text.set('y', str(height / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to center the text on its position we need to define the CSS style of the SVG ''text'' element. Actually we use the ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.set('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we connect all created elements together and put them into the SVG document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer.append(text)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class that inherited from the original effect extension so we have to create an instance of it and execute it in the main control flow:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules to the ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory.  On Linux you will probably have to make the python script executable first if you haven't done this yet.  This is usually done by the usual command (or in your preferred file manager):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ chmod a+x hello_world.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions')&lt;br /&gt;
&lt;br /&gt;
# We will use the inkex module with the predefined Effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
# The simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
Example Inkscape effect extension.&lt;br /&gt;
Creates a new layer with a &amp;quot;Hello World!&amp;quot; text centered in the middle of the document.&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Constructor.&lt;br /&gt;
    Defines the &amp;quot;--what&amp;quot; option of a script.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        # Call the base class constructor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Effect behaviour.&lt;br /&gt;
        Overrides base class' method and inserts &amp;quot;Hello World&amp;quot; text into SVG document.&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        # Get script's &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getroot()&lt;br /&gt;
        # or alternatively&lt;br /&gt;
        # svg = self.document.xpath('//svg:svg',namespaces=inkex.NSS)[0]&lt;br /&gt;
&lt;br /&gt;
        # Again, there are two ways to get the attibutes:&lt;br /&gt;
        width  = inkex.unittouu(svg.get('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.attrib['height'])&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = inkex.etree.SubElement(svg, 'g')&lt;br /&gt;
        layer.set(inkex.addNS('label', 'inkscape'), 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = inkex.etree.Element(inkex.addNS('text','svg'))&lt;br /&gt;
        text.text = 'Hello %s!' % (what)&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.set('x', str(width / 2))&lt;br /&gt;
        text.set('y', str(height / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.set('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        layer.append(text)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Last edited by --[[User:Rubikcube|Rubikcube]] 21:18, 7 August 2008 (UTC), based on a version by&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33854</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33854"/>
		<updated>2008-08-07T21:08:26Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: /* Installation */ added chmod notice&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads an SVG file from standard input, transforms it somehow and prints it to the standart output.  Usually Inkscape sits on both ends, providing the file with some parameters as input first and finally reading the output, which is then used for further work.&lt;br /&gt;
[[Image:Effect_flow.svg|thumb|right|400px]]&lt;br /&gt;
&lt;br /&gt;
We will write a simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
''This script won't work with the current version of inkscape, it might still help as a useful guide how to create your own scripts though.  Especially the methods to access the xml structure have changed, please refer to the [http://codespeak.net/lxml/ lxml] documentation.''&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create a file ''hello_world.py'' and make it executable with the Python interpreter with the well-known directive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import the ''inkex.py'' file with the ''Effect'' base class that will do most of the work for us and the ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare a ''HelloWordEffect'' class that inherits from ''Effect'' and write a constructor where the base class is initialized and script options for the option parser are defined:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The complete documentation for the ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use the ''add_option'' method which has as first argument a short option name, as second argument a long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with the default values specified using the ''.inx'' file for this extension which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide the desired effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you can imagine we just stored the ''--what'' option value to the ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will have to work with the XML representation of the SVG document that we can access via ''Effect'''s ''self.document'' attribute.&lt;br /&gt;
It is of lxml's '' _ElementTree'' class type.  Complete documentation for the lxml package lxml can be found at http://codespeak.net/lxml/.&lt;br /&gt;
&lt;br /&gt;
First we get SVG document's ''svg'' element and its dimensions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getroot()&lt;br /&gt;
        # or alternatively&lt;br /&gt;
        # svg = self.document.xpath('//svg:svg',namespaces=inkex.NSS)[0]&lt;br /&gt;
&lt;br /&gt;
        # Again, there are two ways to get the attibutes:&lt;br /&gt;
        width  = inkex.unittouu(svg.get('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.attrib['height'])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The ''xpath'' function returns a list of all matching elements so we just use the first one of them.&lt;br /&gt;
&lt;br /&gt;
We now create an SVG group element ('' 'g' '') and &amp;quot;mark&amp;quot; it as a layer using Inkscape' SVG extensions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = inkex.etree.SubElement(svg, 'g')&lt;br /&gt;
        layer.set(inkex.addNS('label', 'inkscape'), 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This creates ''inkscape:label'' and ''inkscape:groupmode'' attributes, which will only be read by Inkscape or compatible applications.  To all other viewers, this new element looks just like a plain SVG group.&lt;br /&gt;
&lt;br /&gt;
Now we create an SVG text element with a text value containing the &amp;quot;Hello World&amp;quot; string:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = inkex.etree.Element(inkex.addNS('text','svg'))&lt;br /&gt;
        text.text = 'Hello %s!' % (what)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the position of the text to the center of SVG document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.set('x', str(width / 2))&lt;br /&gt;
        text.set('y', str(height / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to center the text on its position we need to define the CSS style of the SVG ''text'' element. Actually we use the ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.set('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we connect all created elements together and put them into the SVG document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer.append(text)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class that inherited from the original effect extension so we have to create an instance of it and execute it in the main control flow:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules to the ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory.  On Linux you will probably have to make the python script executable first if you haven't done this yet.  This is usually done by the usual command (or in your preferred file manager):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ chmod a+x hello_world.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&lt;br /&gt;
# We will use inex module with predefined effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
 # simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot; Example Inkscape effect extension.&lt;br /&gt;
Creates a new layer with &amp;quot;Hello World!&amp;quot; text centered in middle of document.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Constructor.&lt;br /&gt;
    Defines &amp;quot;--what&amp;quot; option of a script.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        # Call base class construtor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Effect behaviour.&lt;br /&gt;
    Overrides base class' method and insert &amp;quot;Hello World&amp;quot; text in SVG document. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        # Get script &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33844</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33844"/>
		<updated>2008-08-07T21:03:31Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: /* Effect Extension Script */ adapted everything to the lxml package&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads an SVG file from standard input, transforms it somehow and prints it to the standart output.  Usually Inkscape sits on both ends, providing the file with some parameters as input first and finally reading the output, which is then used for further work.&lt;br /&gt;
[[Image:Effect_flow.svg|thumb|right|400px]]&lt;br /&gt;
&lt;br /&gt;
We will write a simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
''This script won't work with the current version of inkscape, it might still help as a useful guide how to create your own scripts though.  Especially the methods to access the xml structure have changed, please refer to the [http://codespeak.net/lxml/ lxml] documentation.''&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create a file ''hello_world.py'' and make it executable with the Python interpreter with the well-known directive:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import the ''inkex.py'' file with the ''Effect'' base class that will do most of the work for us and the ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare a ''HelloWordEffect'' class that inherits from ''Effect'' and write a constructor where the base class is initialized and script options for the option parser are defined:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The complete documentation for the ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use the ''add_option'' method which has as first argument a short option name, as second argument a long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with the default values specified using the ''.inx'' file for this extension which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide the desired effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you can imagine we just stored the ''--what'' option value to the ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will have to work with the XML representation of the SVG document that we can access via ''Effect'''s ''self.document'' attribute.&lt;br /&gt;
It is of lxml's '' _ElementTree'' class type.  Complete documentation for the lxml package lxml can be found at http://codespeak.net/lxml/.&lt;br /&gt;
&lt;br /&gt;
First we get SVG document's ''svg'' element and its dimensions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getroot()&lt;br /&gt;
        # or alternatively&lt;br /&gt;
        # svg = self.document.xpath('//svg:svg',namespaces=inkex.NSS)[0]&lt;br /&gt;
&lt;br /&gt;
        # Again, there are two ways to get the attibutes:&lt;br /&gt;
        width  = inkex.unittouu(svg.get('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.attrib['height'])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The ''xpath'' function returns a list of all matching elements so we just use the first one of them.&lt;br /&gt;
&lt;br /&gt;
We now create an SVG group element ('' 'g' '') and &amp;quot;mark&amp;quot; it as a layer using Inkscape' SVG extensions:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = inkex.etree.SubElement(svg, 'g')&lt;br /&gt;
        layer.set(inkex.addNS('label', 'inkscape'), 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This creates ''inkscape:label'' and ''inkscape:groupmode'' attributes, which will only be read by Inkscape or compatible applications.  To all other viewers, this new element looks just like a plain SVG group.&lt;br /&gt;
&lt;br /&gt;
Now we create an SVG text element with a text value containing the &amp;quot;Hello World&amp;quot; string:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = inkex.etree.Element(inkex.addNS('text','svg'))&lt;br /&gt;
        text.text = 'Hello %s!' % (what)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the position of the text to the center of SVG document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.set('x', str(width / 2))&lt;br /&gt;
        text.set('y', str(height / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want to center the text on its position we need to define the CSS style of the SVG ''text'' element. Actually we use the ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.set('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally we connect all created elements together and put them into the SVG document:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer.append(text)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class that inherited from the original effect extension so we have to create an instance of it and execute it in the main control flow:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules  to ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory and start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&lt;br /&gt;
# We will use inex module with predefined effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
 # simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot; Example Inkscape effect extension.&lt;br /&gt;
Creates a new layer with &amp;quot;Hello World!&amp;quot; text centered in middle of document.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Constructor.&lt;br /&gt;
    Defines &amp;quot;--what&amp;quot; option of a script.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        # Call base class construtor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Effect behaviour.&lt;br /&gt;
    Overrides base class' method and insert &amp;quot;Hello World&amp;quot; text in SVG document. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        # Get script &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33834</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33834"/>
		<updated>2008-08-07T20:44:48Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: /* Effect Extension Script */ corrected some spelling / grammar mistakes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads an SVG file from standard input, transforms it somehow and prints it to the standart output.  Usually Inkscape sits on both ends, providing the file with some parameters as input first and finally reading the output, which is then used for further work.&lt;br /&gt;
[[Image:Effect_flow.svg|thumb|right|400px]]&lt;br /&gt;
&lt;br /&gt;
We will write a simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
''This script won't work with the current version of inkscape, it might still help as a useful guide how to create your own scripts though.  Especially the methods to access the xml structure have changed, please refer to the [http://codespeak.net/lxml/ lxml] documentation.''&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create a file ''hello_world.py'' and make it executable with the Python interpreter with the well-known directive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import the ''inkex.py'' file with the ''Effect'' base class that will do most of the work for us and the ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare a ''HelloWordEffect'' class that inherits from ''Effect'' and write a constructor where the base class is initialized and script options for the option parser are defined:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The complete documentation for the ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use the ''add_option'' method which has as first argument a short option name, as second argument a long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with the default values specified using the ''.inx'' file for this extension which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide the desired effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can imagine we just stored the ''--what'' option value to the ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will have to work with the XML representation of the SVG document that we can access via ''Effect'''s ''self.document'' attribute. It is of ''Document'' class type from ''xml.dom'' module. Complete documentation for this module can be found at http://docs.python.org/lib/module-xml.dom.html.&lt;br /&gt;
&lt;br /&gt;
First get SVG document ''svg'' element and its dimensions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Function ''getElementsByTagName'' returns list of all found elements of this name so we just use first of them.&lt;br /&gt;
&lt;br /&gt;
Create SVG group element and &amp;quot;convert&amp;quot; it to layer using Inkscape SVG extenstions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create SVG text element and its value containing &amp;quot;Hello World&amp;quot;&amp;quot; string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set position of text to center of SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want center text on its position we will define CSS style of SVG ''text'' element. Actually use ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally connect all created elements together and put them in SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class of our effect extension so we have to create an instance of it and execute it in main control flow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules  to ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory and start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&lt;br /&gt;
# We will use inex module with predefined effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
 # simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot; Example Inkscape effect extension.&lt;br /&gt;
Creates a new layer with &amp;quot;Hello World!&amp;quot; text centered in middle of document.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Constructor.&lt;br /&gt;
    Defines &amp;quot;--what&amp;quot; option of a script.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        # Call base class construtor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Effect behaviour.&lt;br /&gt;
    Overrides base class' method and insert &amp;quot;Hello World&amp;quot; text in SVG document. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        # Get script &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33214</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33214"/>
		<updated>2008-07-30T17:41:29Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: Added note about the current state of this example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads an SVG file from standard input, transforms it somehow and prints it to the standart output.  Usually Inkscape sits on both ends, providing the file with some parameters as input first and finally reading the output, which is then used for further work.&lt;br /&gt;
[[Image:Effect_flow.svg|thumb|right|400px]]&lt;br /&gt;
&lt;br /&gt;
We will write a simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
''This script won't work with the current version of inkscape, it might still help as a useful guide how to create your own scripts though.  Especially the methods to access the xml structure have changed, please refer to the [http://codespeak.net/lxml/ lxml] documentation.''&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create a file ''hello_world.py'' and make it executable with the Python interpreter with the well-known directive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import ''inkex.py'' file with ''Effect'' base class that will do most of work for us and ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare ''HelloWordEffect'' class and write a constructor where the base class is initialized and script options for the option parser are defined:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The complete documentation for the ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use the ''add_option'' method which has as first argument a short option name, as second argument a long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with specified default values using ''.inx''. file for this extenstion which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can mention we just stored ''--what'' option value to ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will work with XML representation of SVG document via ''self.document'' attribute. It is of ''Document'' class type from ''xml.dom'' module. Complete documentation for this module can be found at http://docs.python.org/lib/module-xml.dom.html.&lt;br /&gt;
&lt;br /&gt;
First get SVG document ''svg'' element and its dimensions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Function ''getElementsByTagName'' returns list of all found elements of this name so we just use first of them.&lt;br /&gt;
&lt;br /&gt;
Create SVG group element and &amp;quot;convert&amp;quot; it to layer using Inkscape SVG extenstions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create SVG text element and its value containing &amp;quot;Hello World&amp;quot;&amp;quot; string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set position of text to center of SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want center text on its position we will define CSS style of SVG ''text'' element. Actually use ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally connect all created elements together and put them in SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class of our effect extension so we have to create an instance of it and execute it in main control flow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules  to ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory and start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&lt;br /&gt;
# We will use inex module with predefined effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
 # simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot; Example Inkscape effect extension.&lt;br /&gt;
Creates a new layer with &amp;quot;Hello World!&amp;quot; text centered in middle of document.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Constructor.&lt;br /&gt;
    Defines &amp;quot;--what&amp;quot; option of a script.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        # Call base class construtor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Effect behaviour.&lt;br /&gt;
    Overrides base class' method and insert &amp;quot;Hello World&amp;quot; text in SVG document. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        # Get script &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33154</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33154"/>
		<updated>2008-07-30T08:22:35Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads an SVG file from standard input, transforms it somehow and prints it to the standart output.  Usually Inkscape sits on both ends, providing the file with some parameters as input first and finally reading the output, which is then used for further work.&lt;br /&gt;
[[Image:Effect_flow.svg|thumb|right|400px]]&lt;br /&gt;
&lt;br /&gt;
We will write a simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create a file ''hello_world.py'' and make it executable with the Python interpreter with the well-known directive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import ''inkex.py'' file with ''Effect'' base class that will do most of work for us and ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare ''HelloWordEffect'' class and write a constructor where the base class is initialized and script options for the option parser are defined:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The complete documentation for the ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use the ''add_option'' method which has as first argument a short option name, as second argument a long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with specified default values using ''.inx''. file for this extenstion which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can mention we just stored ''--what'' option value to ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will work with XML representation of SVG document via ''self.document'' attribute. It is of ''Document'' class type from ''xml.dom'' module. Complete documentation for this module can be found at http://docs.python.org/lib/module-xml.dom.html.&lt;br /&gt;
&lt;br /&gt;
First get SVG document ''svg'' element and its dimensions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Function ''getElementsByTagName'' returns list of all found elements of this name so we just use first of them.&lt;br /&gt;
&lt;br /&gt;
Create SVG group element and &amp;quot;convert&amp;quot; it to layer using Inkscape SVG extenstions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create SVG text element and its value containing &amp;quot;Hello World&amp;quot;&amp;quot; string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set position of text to center of SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want center text on its position we will define CSS style of SVG ''text'' element. Actually use ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally connect all created elements together and put them in SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class of our effect extension so we have to create an instance of it and execute it in main control flow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules  to ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory and start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&lt;br /&gt;
# We will use inex module with predefined effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
 # simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot; Example Inkscape effect extension.&lt;br /&gt;
Creates a new layer with &amp;quot;Hello World!&amp;quot; text centered in middle of document.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Constructor.&lt;br /&gt;
    Defines &amp;quot;--what&amp;quot; option of a script.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        # Call base class construtor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Effect behaviour.&lt;br /&gt;
    Overrides base class' method and insert &amp;quot;Hello World&amp;quot; text in SVG document. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        # Get script &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33144</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33144"/>
		<updated>2008-07-30T08:15:22Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: Added sketch&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads an SVG file from standard input, transforms it somehow and prints it to the standart output.  Usually Inkscape sits on both ends, providing the file with some parameters as input first and finally reading the output, which is then used for further work.&lt;br /&gt;
[[Image:Effect_flow.svg]]&lt;br /&gt;
&lt;br /&gt;
We will write a simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create a file ''hello_world.py'' and make it executable with the Python interpreter with the well-known directive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import ''inkex.py'' file with ''Effect'' base class that will do most of work for us and ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare ''HelloWordEffect'' class and write a constructor where the base class is initialized and script options for the option parser are defined:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The complete documentation for the ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use the ''add_option'' method which has as first argument a short option name, as second argument a long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with specified default values using ''.inx''. file for this extenstion which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can mention we just stored ''--what'' option value to ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will work with XML representation of SVG document via ''self.document'' attribute. It is of ''Document'' class type from ''xml.dom'' module. Complete documentation for this module can be found at http://docs.python.org/lib/module-xml.dom.html.&lt;br /&gt;
&lt;br /&gt;
First get SVG document ''svg'' element and its dimensions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Function ''getElementsByTagName'' returns list of all found elements of this name so we just use first of them.&lt;br /&gt;
&lt;br /&gt;
Create SVG group element and &amp;quot;convert&amp;quot; it to layer using Inkscape SVG extenstions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create SVG text element and its value containing &amp;quot;Hello World&amp;quot;&amp;quot; string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set position of text to center of SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want center text on its position we will define CSS style of SVG ''text'' element. Actually use ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally connect all created elements together and put them in SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class of our effect extension so we have to create an instance of it and execute it in main control flow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules  to ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory and start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&lt;br /&gt;
# We will use inex module with predefined effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
 # simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot; Example Inkscape effect extension.&lt;br /&gt;
Creates a new layer with &amp;quot;Hello World!&amp;quot; text centered in middle of document.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Constructor.&lt;br /&gt;
    Defines &amp;quot;--what&amp;quot; option of a script.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        # Call base class construtor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Effect behaviour.&lt;br /&gt;
    Overrides base class' method and insert &amp;quot;Hello World&amp;quot; text in SVG document. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        # Get script &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=File:Effect_flow.svg&amp;diff=33134</id>
		<title>File:Effect flow.svg</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=File:Effect_flow.svg&amp;diff=33134"/>
		<updated>2008-07-30T08:07:36Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: Sketch of data flow through inkscape effect scripts&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sketch of data flow through inkscape effect scripts&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33124</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33124"/>
		<updated>2008-07-30T07:59:23Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: Added more info to the first paragraph, some minor corrections&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads an SVG file from standard input, transforms it somehow and prints it to the standart output.  Usually Inkscape sits on both ends, providing the file with some parameters as input first and finally reading the output, which is then used for further work.&lt;br /&gt;
&lt;br /&gt;
We will write a simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create a file ''hello_world.py'' and make it executable with the Python interpreter with the well-known directive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import ''inkex.py'' file with ''Effect'' base class that will do most of work for us and ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare ''HelloWordEffect'' class and write a constructor where the base class is initialized and script options for the option parser are defined:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The complete documentation for the ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use the ''add_option'' method which has as first argument a short option name, as second argument a long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with specified default values using ''.inx''. file for this extenstion which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can mention we just stored ''--what'' option value to ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will work with XML representation of SVG document via ''self.document'' attribute. It is of ''Document'' class type from ''xml.dom'' module. Complete documentation for this module can be found at http://docs.python.org/lib/module-xml.dom.html.&lt;br /&gt;
&lt;br /&gt;
First get SVG document ''svg'' element and its dimensions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Function ''getElementsByTagName'' returns list of all found elements of this name so we just use first of them.&lt;br /&gt;
&lt;br /&gt;
Create SVG group element and &amp;quot;convert&amp;quot; it to layer using Inkscape SVG extenstions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create SVG text element and its value containing &amp;quot;Hello World&amp;quot;&amp;quot; string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set position of text to center of SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want center text on its position we will define CSS style of SVG ''text'' element. Actually use ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally connect all created elements together and put them in SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class of our effect extension so we have to create an instance of it and execute it in main control flow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules  to ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory and start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&lt;br /&gt;
# We will use inex module with predefined effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
 # simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot; Example Inkscape effect extension.&lt;br /&gt;
Creates a new layer with &amp;quot;Hello World!&amp;quot; text centered in middle of document.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Constructor.&lt;br /&gt;
    Defines &amp;quot;--what&amp;quot; option of a script.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        # Call base class construtor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Effect behaviour.&lt;br /&gt;
    Overrides base class' method and insert &amp;quot;Hello World&amp;quot; text in SVG document. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        # Get script &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=Talk:PythonEffectTutorial&amp;diff=33114</id>
		<title>Talk:PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=Talk:PythonEffectTutorial&amp;diff=33114"/>
		<updated>2008-07-30T07:32:06Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: Tutorial still valid for current lxml?&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Current issues==&lt;br /&gt;
Excerpt from an email I sent to the inkscape-devel list:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;Hello,&lt;br /&gt;
I hope this list is the correct one for this kind of question:&lt;br /&gt;
Has anyone managed to get http://wiki.inkscape.org/wiki/index.php/PythonEffectTutorial to work without major changes? It failed for me both on a gentoo system and on a pretty vanilla Ubuntu 8.04 box. I don't know if I will find the time to edit the wiki page according to the current lxml behaviour, but I might give it a try. Additionally Ishmal(I think) said on irc/jabber that lxml might not be used in the future anymore anyway.&lt;br /&gt;
&lt;br /&gt;
Now for the list of problems I encountered:&lt;br /&gt;
* Simply making the file executable and putting it into ~/.inkscape/extensions/ is not sufficient, it won't find inkex there, but no problem, simply add&lt;br /&gt;
  import sys&lt;br /&gt;
  sys.path.append('/usr/share/inkscape/extensions') # or another path, as appropriate for your installation&lt;br /&gt;
to the top of it.  A minor problem.&lt;br /&gt;
* All the getElementsByTagName, getAttribute, createElement,... methods are unknown to lxml, at least in the versions here (1.3.6). Inkscape returns the python error message ending with:&lt;br /&gt;
  File &amp;quot;/home/dhornun/.inkscape/extensions/helloworld.py&amp;quot;, line 32, in effect&lt;br /&gt;
      svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
  AttributeError: 'etree._ElementTree' object has no attribute 'getElementsByTagName'&lt;br /&gt;
If this is not a problem on the distributions' side, those can probably be fixed by adapting the code to reflect lxml's current API.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
Hopefully I'll find the time to fix this either on my machine or here in the wiki.  The first point was fixed already. --[[User:Rubikcube|Rubikcube]] 07:32, 30 July 2008 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33104</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33104"/>
		<updated>2008-07-30T07:21:03Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: /* Complete Source Code */ Added to path&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads input SVG file transforms it somehow and prints it to the standart output.&lt;br /&gt;
&lt;br /&gt;
We will write simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create file ''hello_world.py'' and make them executable with Python interpreter with well-known directive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import ''inkex.py'' file with ''Effect'' base class that will do most of work for us and ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare ''HelloWordEffect'' class and write a constructor where base class is initialized and script option for opition parser is defined:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Complete documentation for ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use ''add_option'' method which has as first argument short option name, as second argument long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with specified default values using ''.inx''. file for this extenstion which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can mention we just stored ''--what'' option value to ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will work with XML representation of SVG document via ''self.document'' attribute. It is of ''Document'' class type from ''xml.dom'' module. Complete documentation for this module can be found at http://docs.python.org/lib/module-xml.dom.html.&lt;br /&gt;
&lt;br /&gt;
First get SVG document ''svg'' element and its dimensions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Function ''getElementsByTagName'' returns list of all found elements of this name so we just use first of them.&lt;br /&gt;
&lt;br /&gt;
Create SVG group element and &amp;quot;convert&amp;quot; it to layer using Inkscape SVG extenstions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create SVG text element and its value containing &amp;quot;Hello World&amp;quot;&amp;quot; string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set position of text to center of SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want center text on its position we will define CSS style of SVG ''text'' element. Actually use ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally connect all created elements together and put them in SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class of our effect extension so we have to create an instance of it and execute it in main control flow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules  to ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory and start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# These two lines are only needed if you don't put the script directly into&lt;br /&gt;
# the installation directory&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&lt;br /&gt;
# We will use inex module with predefined effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
 # simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot; Example Inkscape effect extension.&lt;br /&gt;
Creates a new layer with &amp;quot;Hello World!&amp;quot; text centered in middle of document.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Constructor.&lt;br /&gt;
    Defines &amp;quot;--what&amp;quot; option of a script.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        # Call base class construtor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Effect behaviour.&lt;br /&gt;
    Overrides base class' method and insert &amp;quot;Hello World&amp;quot; text in SVG document. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        # Get script &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33094</id>
		<title>PythonEffectTutorial</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=PythonEffectTutorial&amp;diff=33094"/>
		<updated>2008-07-30T07:19:39Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: /* Effect Extension Script */ path added&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Effect extensions in Inkscape means a simple programs or scripts that reads input SVG file transforms it somehow and prints it to the standart output.&lt;br /&gt;
&lt;br /&gt;
We will write simple effect extension script in Python that will put &amp;quot;Hello World!&amp;quot; or &amp;quot;Hello &amp;lt;value of --what option&amp;gt;!&amp;quot; string in the center of document and inside a new layer.&lt;br /&gt;
&lt;br /&gt;
== Effect Extension Script ==&lt;br /&gt;
&lt;br /&gt;
First of all create file ''hello_world.py'' and make them executable with Python interpreter with well-known directive:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're going to put the file somewhere else than into inkscape's installation directory, we need to add a path so that python can find the necessary modules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path.append('/usr/share/inkscape/extensions') # or another path, as necessary&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Import ''inkex.py'' file with ''Effect'' base class that will do most of work for us and ''simplestyle.py'' module with support functions for working with CSS styles. We will use just the ''formatStyle'' function from this module.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import inkex&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Declare ''HelloWordEffect'' class and write a constructor where base class is initialized and script option for opition parser is defined:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Complete documentation for ''OptionParser'' class can be found at http://docs.python.org/lib/module-optparse.html. Here we just use ''add_option'' method which has as first argument short option name, as second argument long option name and then a few other arguments with this meaning:&lt;br /&gt;
&lt;br /&gt;
* ''action'' - An action which should be done with option value. In this case we use action ''store'' which will store option value in ''self.options.&amp;lt;destination&amp;gt;'' attribute.&lt;br /&gt;
* ''type'' - Type of option value. We use string here.&lt;br /&gt;
* ''dest'' - Destination of option action specified by ''action'' argument. Using ''what'' value we say that we want to store option value to self.options.what attribute.&lt;br /&gt;
* ''default'' - Defalut value for this option if it is not specified.&lt;br /&gt;
* ''help'' - A help string that will be displayed if script will be given no arguments or some option or argument will have wrong syntax.&lt;br /&gt;
&lt;br /&gt;
Inkscape will create a GUI form with widgets for all specified options and prefill them with specified default values using ''.inx''. file for this extenstion which we will write later. &lt;br /&gt;
&lt;br /&gt;
We need to override only one ''Effect'' class method to provide effect functionality: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can mention we just stored ''--what'' option value to ''what'' variable.&lt;br /&gt;
&lt;br /&gt;
Now we will finally start to do something. We will work with XML representation of SVG document via ''self.document'' attribute. It is of ''Document'' class type from ''xml.dom'' module. Complete documentation for this module can be found at http://docs.python.org/lib/module-xml.dom.html.&lt;br /&gt;
&lt;br /&gt;
First get SVG document ''svg'' element and its dimensions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Function ''getElementsByTagName'' returns list of all found elements of this name so we just use first of them.&lt;br /&gt;
&lt;br /&gt;
Create SVG group element and &amp;quot;convert&amp;quot; it to layer using Inkscape SVG extenstions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create SVG text element and its value containing &amp;quot;Hello World&amp;quot;&amp;quot; string:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set position of text to center of SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we want center text on its position we will define CSS style of SVG ''text'' element. Actually use ''text-anchor'' SVG extension to CSS styles to do that work:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor' : 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally connect all created elements together and put them in SVG document:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We just defined a class of our effect extension so we have to create an instance of it and execute it in main control flow:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Extension Description File ==&lt;br /&gt;
&lt;br /&gt;
To include script in Inkscape's main menu create ''hello_world.inx'' file describing script evokation. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;inkscape-extension&amp;gt;&lt;br /&gt;
  &amp;lt;_name&amp;gt;Hello World!&amp;lt;/_name&amp;gt;&lt;br /&gt;
  &amp;lt;id&amp;gt;org.ekips.filter.hello_world&amp;lt;/id&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;hello_world.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;dependency type=&amp;quot;executable&amp;quot; location=&amp;quot;extensions&amp;quot;&amp;gt;inkex.py&amp;lt;/dependency&amp;gt;&lt;br /&gt;
  &amp;lt;param name=&amp;quot;what&amp;quot; type=&amp;quot;string&amp;quot; _gui-text=&amp;quot;What would you like to greet?&amp;quot;&amp;gt;World&amp;lt;/param&amp;gt;&lt;br /&gt;
  &amp;lt;effect&amp;gt;&lt;br /&gt;
    &amp;lt;object-type&amp;gt;all&amp;lt;/object-type&amp;gt;&lt;br /&gt;
    &amp;lt;effects-menu&amp;gt;&lt;br /&gt;
       &amp;lt;submenu _name=&amp;quot;Examples&amp;quot;/&amp;gt;&lt;br /&gt;
    &amp;lt;/effects-menu&amp;gt;&lt;br /&gt;
  &amp;lt;/effect&amp;gt;&lt;br /&gt;
  &amp;lt;script&amp;gt;&lt;br /&gt;
    &amp;lt;command reldir=&amp;quot;extensions&amp;quot; interpreter=&amp;quot;python&amp;quot;&amp;gt;hello_world.py&amp;lt;/command&amp;gt;&lt;br /&gt;
  &amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/inkscape-extension&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create ''&amp;lt;param&amp;gt;'' element for every option of a script and ''&amp;lt;dependency&amp;gt;'' for every included module which is not from Python standard library. Inkscape will search for this modules in directory with script. ''&amp;lt;effect&amp;gt;'' element and its descendants defines name of menu item evoking our new &amp;quot;Hello World!&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
If the inx file isn't well formed or if any of the dependencies wasn't met, the extension won't show up in the menu. If your extension doesn't show up, take a look at extension-errors.log, which may give you a hint why it wasn't loaded.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
To install a new extenstion just put ''hello_world.py'' and ''hello_world.inx'' files with all dependency modules  to ''&amp;lt;path_to_inkscape&amp;gt;/extensions'' or ''~/.inkscape/extensions'' directory and start Inkscape. A new menu item ''Hello World!'' in ''Effects-&amp;gt;Examples'' menu should appear.&lt;br /&gt;
&lt;br /&gt;
== Complete Source Code ==&lt;br /&gt;
&lt;br /&gt;
Here is a complete commented source pre of ''hello_world.py'' script file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# We will use inex module with predefined effect base class.&lt;br /&gt;
import inkex&lt;br /&gt;
 # simplestyle module provides functions for style parsing.&lt;br /&gt;
from simplestyle import *&lt;br /&gt;
&lt;br /&gt;
&amp;quot;&amp;quot;&amp;quot; Example Inkscape effect extension.&lt;br /&gt;
Creates a new layer with &amp;quot;Hello World!&amp;quot; text centered in middle of document.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
class HelloWorldEffect(inkex.Effect):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Constructor.&lt;br /&gt;
    Defines &amp;quot;--what&amp;quot; option of a script.&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        # Call base class construtor.&lt;br /&gt;
        inkex.Effect.__init__(self)&lt;br /&gt;
&lt;br /&gt;
        # Define string option &amp;quot;--what&amp;quot; with &amp;quot;-w&amp;quot; shortcut and default value &amp;quot;World&amp;quot;.&lt;br /&gt;
        self.OptionParser.add_option('-w', '--what', action = 'store',&lt;br /&gt;
          type = 'string', dest = 'what', default = 'World',&lt;br /&gt;
          help = 'What would you like to greet?')&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Effect behaviour.&lt;br /&gt;
    Overrides base class' method and insert &amp;quot;Hello World&amp;quot; text in SVG document. &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def effect(self):&lt;br /&gt;
        # Get script &amp;quot;--what&amp;quot; option value.&lt;br /&gt;
        what = self.options.what&lt;br /&gt;
&lt;br /&gt;
        # Get access to main SVG document element and get its dimensions.&lt;br /&gt;
        svg = self.document.getElementsByTagName('svg')[0]&lt;br /&gt;
        width = inkex.unittouu(svg.getAttribute('width'))&lt;br /&gt;
        height = inkex.unittouu(svg.getAttribute('height'))&lt;br /&gt;
&lt;br /&gt;
        # Create a new layer.&lt;br /&gt;
        layer = self.document.createElement('g')&lt;br /&gt;
        layer.setAttribute('inkscape:label', 'Hello %s Layer' % (what))&lt;br /&gt;
        layer.setAttribute('inkscape:groupmode', 'layer')&lt;br /&gt;
&lt;br /&gt;
        # Create text element&lt;br /&gt;
        text = self.document.createElement('text')&lt;br /&gt;
        value = self.document.createTextNode('Hello %s!' % (what))&lt;br /&gt;
&lt;br /&gt;
        # Set text position to center of document.&lt;br /&gt;
        text.setAttribute('x', str(width / 2))&lt;br /&gt;
        text.setAttribute('y', str(height  / 2))&lt;br /&gt;
&lt;br /&gt;
        # Center text horizontally with CSS style.&lt;br /&gt;
        style = {'text-align' : 'center', 'text-anchor': 'middle'}&lt;br /&gt;
        text.setAttribute('style', formatStyle(style))&lt;br /&gt;
&lt;br /&gt;
        # Connect elements together.&lt;br /&gt;
        text.appendChild(value)&lt;br /&gt;
        layer.appendChild(text)&lt;br /&gt;
        svg.appendChild(layer)&lt;br /&gt;
&lt;br /&gt;
# Create effect instance and apply it.&lt;br /&gt;
effect = HelloWorldEffect()&lt;br /&gt;
effect.affect()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[User:Blackhex|Blackhex]] 11:59, 26 April 2007 (UTC)&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=TutorialIdeas&amp;diff=7650</id>
		<title>TutorialIdeas</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=TutorialIdeas&amp;diff=7650"/>
		<updated>2006-07-17T11:43:10Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: /* Tutorials in development */ link updated for isometric transformations&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will consist of brainstorming and basic development of new tutorials that will be useful for new/old users.&lt;br /&gt;
&lt;br /&gt;
Also see [[TutorialsAndHelp]]&lt;br /&gt;
&lt;br /&gt;
=== Completed Tutorials ===&lt;br /&gt;
&lt;br /&gt;
* [[DefaultTutorial]]&lt;br /&gt;
* [http://home.programmer-art.org/?page=inkscape Daniel Taylor's Web-Based Inkscape Tutorials] - Hopefully he will make SVG tutorials that we can inlude with Inkscape, like our current [[DefaultTutorial]].&lt;br /&gt;
* making shiny marbles... http://inkscape.org/wiki_uploads/marbles_tut.svg&lt;br /&gt;
* also see [http://inkscape.org/cgi-bin/wiki.pl?OtherProjects#outsidetut Outside Tutorials and Tips]&lt;br /&gt;
* [[ElementsPrinciplesOfDesign]] (rejon)&lt;br /&gt;
* [http://kargs.net/docs/easter_egg_tutorial.svg Easter Egg Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== Tutorials in development ===&lt;br /&gt;
&lt;br /&gt;
* [http://homepage.univie.ac.at/reinhard.stepanek/fxos80/metchart.html How to create meteorological charts with Inkscape], Tutorial by Reinhard Stepanek&lt;br /&gt;
* Daniel Pope's Clownfish Tutorial - [http://www.mauveweb.co.uk/misc/tutorials/clownfish.svg Part 1] [http://www.mauveweb.co.uk/misc/tutorials/clownfish2.svg Part 2] - drop me an email at mauve@mauveweb.co.uk to suggest changes.&lt;br /&gt;
* A very small sheet with instructions for doing  [http://www.gimpforum.de/album/file.php?n=4323&amp;amp;w=o isometric transformations] - if anyone has comments or wants to have a look at the original svg, contact me at daniel dot hornung &amp;lt;at&amp;gt; gmx dot de&lt;br /&gt;
&lt;br /&gt;
=== Planned Tutorials ===&lt;br /&gt;
&lt;br /&gt;
* [[UsingTheCloneTiler]] - Clones&lt;br /&gt;
&lt;br /&gt;
* Text and Typography&lt;br /&gt;
&lt;br /&gt;
* Clippath/Mask/Pattern&lt;br /&gt;
&lt;br /&gt;
* Effects&lt;br /&gt;
&lt;br /&gt;
* SVG Filters&lt;br /&gt;
&lt;br /&gt;
* XML Editor&lt;br /&gt;
&lt;br /&gt;
=== Tutorial Scratchpad ===&lt;br /&gt;
&lt;br /&gt;
* How to create an icon&lt;br /&gt;
* How to build a presentation using Inkview.&lt;br /&gt;
* How to build complex shapes using boolean operations.&lt;br /&gt;
* How to use Inkscape to create graphics for LaTeX / ConTeXt documents.&lt;br /&gt;
* etc&lt;br /&gt;
&lt;br /&gt;
A tutorial in progress of writing by John Griessen&lt;br /&gt;
&lt;br /&gt;
This writing is a journal of how a project to recreate a business card originally &lt;br /&gt;
made with Illutrator 7, after losing the original file, so the comparison to Illustrator is &lt;br /&gt;
much from memory and not to be taken as the last word, but a guide as to how the programs compare.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Attached is a png of the printed business card:&lt;br /&gt;
&lt;br /&gt;
It originally was a collection of paths filled with colors and text objects with grouping to&lt;br /&gt;
make replicating some objects easy.  &lt;br /&gt;
&lt;br /&gt;
The shell command  '$inkscape --version' tells us this is Inkscape 0.39cvs (Jul  2 2004)  .&lt;br /&gt;
&lt;br /&gt;
The logo main element is a pseudo sine wave, and I made it before with grid snap and stretching and replicating, so now I set my units to mm and grid spacing and snap to 1 and remember how it would be nice to have major and minor grids instead of just one, so I want to create some vertical guides evenly spaced and cannot remember and start looking in docs.  In Illustrator 7, clicking on the ruler bar created a guide if I recall...  Once created, it could be moved with grid snap like any object, so getting it on grid or off was easy.  As I read around, I find the usage of guides in &amp;quot;Keys and Mouse&amp;quot;  &amp;quot;drag off a ruler&amp;quot;  is the way...  and a guide is on the page, and I can't snap it to easily make the accurate secondary grid I had wanted....Is there a way to?  I try duplicate on the guide, but alas, it is not a regular object...  it cannot be selected as they are...so I cannot replicate guides to make other grids after all... note for the beginner, to get bezier curves out of the line/bezier tool, you must click-drag.  A click-only will give you only connected straight line segments.   I'll have to use lines as guides, &lt;br /&gt;
http://home.austin.rr.com/jgriessen/ill2ink-tut1.png&lt;br /&gt;
&lt;br /&gt;
[[Category:Help Wanted]]&lt;br /&gt;
&lt;br /&gt;
=== Other SVG Tutorials ===&lt;br /&gt;
&lt;br /&gt;
* http://www.codeproject.com/books/learnsvgchapter07.asp&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
	<entry>
		<id>https://wiki.inkscape.org/wiki/index.php?title=TutorialIdeas&amp;diff=7639</id>
		<title>TutorialIdeas</title>
		<link rel="alternate" type="text/html" href="https://wiki.inkscape.org/wiki/index.php?title=TutorialIdeas&amp;diff=7639"/>
		<updated>2006-07-17T00:07:31Z</updated>

		<summary type="html">&lt;p&gt;Rubikcube: /* Tutorials in development */ added tutorial for isometric transforms&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page will consist of brainstorming and basic development of new tutorials that will be useful for new/old users.&lt;br /&gt;
&lt;br /&gt;
Also see [[TutorialsAndHelp]]&lt;br /&gt;
&lt;br /&gt;
=== Completed Tutorials ===&lt;br /&gt;
&lt;br /&gt;
* [[DefaultTutorial]]&lt;br /&gt;
* [http://home.programmer-art.org/?page=inkscape Daniel Taylor's Web-Based Inkscape Tutorials] - Hopefully he will make SVG tutorials that we can inlude with Inkscape, like our current [[DefaultTutorial]].&lt;br /&gt;
* making shiny marbles... http://inkscape.org/wiki_uploads/marbles_tut.svg&lt;br /&gt;
* also see [http://inkscape.org/cgi-bin/wiki.pl?OtherProjects#outsidetut Outside Tutorials and Tips]&lt;br /&gt;
* [[ElementsPrinciplesOfDesign]] (rejon)&lt;br /&gt;
* [http://kargs.net/docs/easter_egg_tutorial.svg Easter Egg Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== Tutorials in development ===&lt;br /&gt;
&lt;br /&gt;
* [http://homepage.univie.ac.at/reinhard.stepanek/fxos80/metchart.html How to create meteorological charts with Inkscape], Tutorial by Reinhard Stepanek&lt;br /&gt;
* Daniel Pope's Clownfish Tutorial - [http://www.mauveweb.co.uk/misc/tutorials/clownfish.svg Part 1] [http://www.mauveweb.co.uk/misc/tutorials/clownfish2.svg Part 2] - drop me an email at mauve@mauveweb.co.uk to suggest changes.&lt;br /&gt;
* A very small sheet with instructions for doing  [http://www.gimpforum.de/album/images/791/1_isometric.png isometric transforms] - if anyone has comments or wants to have the original svg, contact me at daniel dot hornung &amp;lt;at&amp;gt; gmx dot de&lt;br /&gt;
&lt;br /&gt;
=== Planned Tutorials ===&lt;br /&gt;
&lt;br /&gt;
* [[UsingTheCloneTiler]] - Clones&lt;br /&gt;
&lt;br /&gt;
* Text and Typography&lt;br /&gt;
&lt;br /&gt;
* Clippath/Mask/Pattern&lt;br /&gt;
&lt;br /&gt;
* Effects&lt;br /&gt;
&lt;br /&gt;
* SVG Filters&lt;br /&gt;
&lt;br /&gt;
* XML Editor&lt;br /&gt;
&lt;br /&gt;
=== Tutorial Scratchpad ===&lt;br /&gt;
&lt;br /&gt;
* How to create an icon&lt;br /&gt;
* How to build a presentation using Inkview.&lt;br /&gt;
* How to build complex shapes using boolean operations.&lt;br /&gt;
* How to use Inkscape to create graphics for LaTeX / ConTeXt documents.&lt;br /&gt;
* etc&lt;br /&gt;
&lt;br /&gt;
A tutorial in progress of writing by John Griessen&lt;br /&gt;
&lt;br /&gt;
This writing is a journal of how a project to recreate a business card originally &lt;br /&gt;
made with Illutrator 7, after losing the original file, so the comparison to Illustrator is &lt;br /&gt;
much from memory and not to be taken as the last word, but a guide as to how the programs compare.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Attached is a png of the printed business card:&lt;br /&gt;
&lt;br /&gt;
It originally was a collection of paths filled with colors and text objects with grouping to&lt;br /&gt;
make replicating some objects easy.  &lt;br /&gt;
&lt;br /&gt;
The shell command  '$inkscape --version' tells us this is Inkscape 0.39cvs (Jul  2 2004)  .&lt;br /&gt;
&lt;br /&gt;
The logo main element is a pseudo sine wave, and I made it before with grid snap and stretching and replicating, so now I set my units to mm and grid spacing and snap to 1 and remember how it would be nice to have major and minor grids instead of just one, so I want to create some vertical guides evenly spaced and cannot remember and start looking in docs.  In Illustrator 7, clicking on the ruler bar created a guide if I recall...  Once created, it could be moved with grid snap like any object, so getting it on grid or off was easy.  As I read around, I find the usage of guides in &amp;quot;Keys and Mouse&amp;quot;  &amp;quot;drag off a ruler&amp;quot;  is the way...  and a guide is on the page, and I can't snap it to easily make the accurate secondary grid I had wanted....Is there a way to?  I try duplicate on the guide, but alas, it is not a regular object...  it cannot be selected as they are...so I cannot replicate guides to make other grids after all... note for the beginner, to get bezier curves out of the line/bezier tool, you must click-drag.  A click-only will give you only connected straight line segments.   I'll have to use lines as guides, &lt;br /&gt;
http://home.austin.rr.com/jgriessen/ill2ink-tut1.png&lt;br /&gt;
&lt;br /&gt;
[[Category:Help Wanted]]&lt;br /&gt;
&lt;br /&gt;
=== Other SVG Tutorials ===&lt;br /&gt;
&lt;br /&gt;
* http://www.codeproject.com/books/learnsvgchapter07.asp&lt;/div&gt;</summary>
		<author><name>Rubikcube</name></author>
	</entry>
</feed>