0-Set up

Each extension requires two files: a .py file and a .inx file
We are going to set up these two files
Navigate to your Inkscape installation folder and go to this path: Inkscape\share\extensions

Extensions folder


This is the path were Inkscape extensions files are saved.
Have a browse and you will see mainly two type of files .py and .inx

Before we write any code we need to create 2 files in this directory:

The first one  animate.py will contain our code.
The second one animate.inx will contain our parameters.

Download the two files and copy them into the "extensions" folder.
If Inkscape is already open, close it.
(Re)Open Inkscape navigate to the "Extensions Tab" and you should see a new menu being added "MyExtension" containing "Animate"



If you have the same as the above, Congratulation your Script have been set up Successfully!

If we click on "animate" a blank window will appear briefly but nothing happens.
Of course we have not written any code yet!
In the next Act, we will create  message box displaying "Hello World!" on the screen.



Here I will show you what is inside the two files so that you can experiment creating your own .py and .inx

First you need an editor to view the content of the file, I used to use PsPad  until last week when I discovered the new cross platform Microsoft Editor, and it really is awesome and free :) and open source! one of our friend!
You can download it for your operating systems here:
https://code.visualstudio.com/Download
Once install, download the Python extension from within the software or you can download it here:
https://marketplace.visualstudio.com/items?itemName=ms-python.python

But if you are used to another editor, feel free to stick to it.

The .inx file essentially tell Inkscape where to install your script on the Windows interface,
For this first set of  tutorials, I have installed it under the "Extensions" tab, which is the usual place for extensions.
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
    <!-- Name which will appear under the submenu -->
    <_name>animate</_name>
    <!-- This is can be used to create a keyboard shorcut for the extension -->
    <id>org.inkscape.animate</id>
    <effect>        
        <effects-menu>
            <!-- Create a new submenu called "All my extensions" -->
            <submenu _name="All my extensions"/>           
        </effects-menu>
    </effect>
    <script>                
        <!-- Our new Submenu will be under the "extensions" menu -->
        <!-- Our extension will run the file animate.py -->
        <command reldir="extensions" interpreter="python">animate.py</command>              
    </script>
</inkscape-extension>
Most of the time I will leave comments in the .inx file to explain the purpose of a  specific line
Comment are displayed like so:
<!-- This line is a comment -->

Here the comments explain what the line directly above them are doing, for example, This following line:
<command reldir="extensions" interpreter="python">animate.py</command>        
 put the Sub-menu under the Extensions menu, and also tell Inkscape to run
animate.py script when you click on animate

IMAGE OF THE SUBMENU

So if you want the name of the script to be different you just change
<_name>animate</_name>   to  <_name>my own name</_name>
and if you want to submenu name to be different you just change:
<submenu _name="All my extensions"/> to <submenu _name="My Submenu name"/>

For every script you create you we will also create an .inx associated to it.
I am planning to do a full tutorial on .inx files but that's all we need to know for now.

Now onto the python file:
The .py file is the instruction file and this is where you will spend the majority of your time... coding and make things happens!

#!/usr/bin/env python

import inkex

class Animate(inkex.Effect):
  def effect(self):
    #This is where we will write our code

    return

a = Animate()
a.affect()

As you can see it is smaller then the .inx file, but no worries it will be significantly bigger as we do more things!

I will also leave some comments in the python file
#This is what a comment looks like in a Python file


Next: Hello World!
or
Back to the index






1 comment:

  1. This is excellent, I can't wait to try it out! Thanks for all the time and hard work...

    ReplyDelete