Difference between revisions of "Script extensions"
m (moved ScriptingHOWTO to Script extensions: kill wikiwords) |
(→Introduction: copy-edit) |
||
Line 3: | Line 3: | ||
=== Introduction === | === Introduction === | ||
Inkscape | Traditional unix scripts can be used to extend Inkscape's functionality. | ||
Such programs read a stream of data on standard input, transform the data in some way, and then write the modified data to standard output. This is an easy way to expand Inkscape and provide custom functionality without learning the internals of Inkscape. Libraries for reading and writing SVG data exist for many programming languages, and most provide support for XML. This HOWTO describes the "ins and outs" of writing one of these scripts and making it work with Inkscape's core functionality. | |||
=== Types of scripts === | === Types of scripts === |
Revision as of 15:28, 13 July 2009
[Note: This page concerns using scripting languages to create new Inkscape functionality. To access Inkscape functionality from scripting languages (i.e. to script Inkscape), see the Inkscape man page (especially in the development version or v0.46 or later, which provide --select and --verb options), or see the work in the src/extension/script directory of Inkscape source.]
Introduction
Traditional unix scripts can be used to extend Inkscape's functionality. Such programs read a stream of data on standard input, transform the data in some way, and then write the modified data to standard output. This is an easy way to expand Inkscape and provide custom functionality without learning the internals of Inkscape. Libraries for reading and writing SVG data exist for many programming languages, and most provide support for XML. This HOWTO describes the "ins and outs" of writing one of these scripts and making it work with Inkscape's core functionality.
Types of scripts
There are three kinds of functions that can be added with a script:
- Input, providing translation from a file format to SVG
- Output, providing translation from SVG to a format
- Effect, taking in SVG, changing it, and then outputing SVG
While all of these are very similar in the scripting interface, there are slight differences between them.
Interaction
It is important for a script author to understand how Inkscape and scripts communicate.
(interpreter)? your_script (--param=value)* /path/to/input/SVGfile | inkscape
Inkscape runs your script (optionally with an interpreter) passing it any number of parameters in long gnu style. The final argument is the name of the temporary svg file your script should read. After processing, the script should return the modified svg file to inkscape on STDOUT.
Important Tips
- Receive the inkscape arguments.
- Clear temp files if it creates one.
- Write full changed SVG to the default output.
- Don't break an xml:space="preserve" area.
- Send error text to the error output and help the user.
Description
In order for Inkscape to make use of an external script or program, you must describe that script to inkscape using an INX file. See the inkscape share directory for examples. The INX file allows the author to:
- label strings for translation
- define parameters
- chain extensions
Please see MakingAnINX for help creating an INX file for your script.
Parameters
The INX file describes which parameters the extension needs. Inkscape will prompt the user with a UI to fill out these parameters before the extension is called. Each parameter will be passed through the commandline as "--paramname=paramvalue". Eg. if you have described a string parameter with name 'string1' in the INX file, Inkscape will present a textbox to the user. When the user fills in "text" and presses OK, it will pass '--string1="text"' to the program specified by the <command> tag.
There are several types of parameters that can be requested by the INX description:
- Boolean
- Int
- Float
- String
- Description
- Enum
- Notebook
- Option group (radio buttons)
Installing
Installing is as simple as copying the script (unless it resides in your path) and its INX file to the inkscape/share/extensions (home/.inkscape/extensions) directory. (If you install a script in your home directory be sure to copy the dependencies.)
If you are looking to use scripts that have already been written, the most difficult part will likely be the installation. Since scripts are seperate programs they may have any number of dependencies that are not included with inkscape. Currently, the best way to find missing dependencies is by reading the error messages produced by running the script from the command line.
See Also
- Aarons website describing his path to learning how scripting extensions work. VERY OUT-OF-DATE