Inkscape.org
Creating New Extensions Help to get started coding extensions
  1. #1
    Gwenaël Gwenaël @GwenaelQ.

    Hi all,

    I would like to write some modest extensions (for my personnal use at first) but my programming skills are quite limited although I like scripting. Despite my searches i keep struggling on how to get started with path manipulations. I'm probably missing some (obvious ?) things...

    I dug into :

    - [The extension page](https://inkscape.org/develop/extensions/)

    - [The API page](https://inkscape.gitlab.io/extensions/documentation/)

    - [Common classes](https://inkscape.gitlab.io/inkscape/doxygen-extensions/CommonClasses.html)

    - and the extensions in the extension folder of Inkscape,

    with no success. I suppose I would finally manage but I already spent a lot of days trying... I would very much appreciate if someone could help me alleviate my efforts, showing the best or simpler python code to, let say, simply rotate selected objects (with simplepath.rotatePath or wichever better way).

    Many thanks in advance.

     

     

  2. #2
    Gwenaël Gwenaël @GwenaelQ.
    *

    Hi all,

    Perhaps adding what I already did (that doesn't work) will move a charitable soul... ;-) The extension runs without error but nothing happens ! 

    Rotation_attempt.py :

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    # These two lines are only needed if you don't put the script directly into
    # the installation directory.
    import sys
    sys.path.append('/usr/share/inkscape/extensions')
    
    import simplepath
    import inkex
    
    class Rotation(inkex.Effect):
        """
        Example Inkscape effect extension.
        Rotates selected path
        """
        def __init__(self):
            """
            Constructor.
            """
            # Call the base class constructor.
            inkex.Effect.__init__(self)
    
        def effect(self):
            """
            Effect behaviour.
            Overrides base class' method .
            """
            selection = self.selected
    
            if (selection):
                for id, node in selection.iteritems():
                     p = simplepath.parsePath(node.get('d'))
                     simplepath.rotatePath( p, 25, 0, 0 )
            else:
                inkex.errormsg("Please select an object.")
    
    # Create effect instance and apply it.
    effect = Rotation()
    effect.affect()

    Rotation_attempt.inx

    <?xml version="1.0" encoding="UTF-8"?>
    <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
      <_name>Rotation_attempt</_name>
      <id>inkscape.org.rotation.attempt</id>
      <effect>
        <object-type>all</object-type>
        <effects-menu>
           <submenu _name="User"/>
        </effects-menu>
      </effect>
      <script>
        <command reldir="extensions" interpreter="python">Rotation_attempt.py</command>
      </script>
    </inkscape-extension>

    Thank you for helping !

  3. #3
    Marco Riva Marco Riva @zerocinquanta
    **

    Hello, I think these links could help, too

     

    http://vectorgraphicsanimation.blogspot.com/2018/04/writing-extensions-for-inkscape.html

     

    https://medium.com/%40xaviju/inkscape-extensions-by-non-developers-for-non-developers-a-primer-b272dda360fe

  4. #4
    Maren Hachmann Maren Hachmann @Moini

    Marco, those pages don't apply to the 1.0 version, unfortunately. Things have changed quite a bit, and not all of it is documented yet. For the basic hello-world extensions, the changes would be relatively small, but the articles would still need an update.

  5. #5
    Maren Hachmann Maren Hachmann @Moini

    Gwenael, best compare with an existing extension for the Inkscape version of your choice. If you want to continue using the extension you're writing in the future, you could start with one for 1.0 (those won't work with 0.92.x, and vice versa (for many)).

  6. #6
    Marco Riva Marco Riva @zerocinquanta

    Ops, I see, Maren. My info are valid only up to 0.92.

  7. #7
    Tartess5952 Tartess5952 @Tartess5952

    @Gwenaël, please would you now three years later be a charitable soul to give a quick simple tutorial on getting started with plugin development, there seems to be little literature on the subject and your post has taken number one google search result on the subject.

  8. #8
    inklinea inklinea @inklinea⛰️

    This is currently the start page for the extension tutorial, the next page is called 'My First Effect Extension'

    https://inkscape.gitlab.io/extensions/documentation/tutorial/index.html

    it's been rewritten since the original post in 2020 :)

    If you need a simple example for something in particular - ask.

Inkscape Inkscape.org Inkscape Forum Creating New Extensions Help to get started coding extensions