![]() |
Home Compute Inkscape Contact | ![]() |
|||||
Watch and LearnTo see how this all works I thought it would be a good idea to create an effect that captures interaction between Inkscape and a script without altering the SVG. Using dropshadow.inx as my base I created as simple an *.inx file as possible.
<inkscape-extension>
<name>Capture Interaction</name>
<id>org.ekips.filter.capture</id>
<dependency type="executable" location="extensions">capture.py</dependency>
<effect>
<object-type>all</object-type>
</effect>
<script>
<command reldir="extensions">capture.py</command>
</script>
</inkscape-extension>
Then I created a Python script to capture command line arguments and standard input.
#!/usr/bin/env python
"""
capture.py
Captures interaction from Inkscape into files in the temp directory
"""
import sys, tempfile, shutil
outdir = tempfile.gettempdir()
#capture the arguments
f_args = open(outdir + '/ink_capture_args.txt', 'w')
f_args.write(" ".join(sys.argv) + '\n')
f_args.close()
'''
#capture STDIN
#notice STDIN is empty, I wasn't expecting this
f_in = open(outdir + '/ink_capture_stdin.txt', 'w')
for line in sys.stdin:
f_in.write(line)
f_in.close()
'''
#the final argument is the path of a temporary file
#that contains the SVG document
#capture that file
svgfile = sys.argv[-1:][0]
shutil.copy(svgfile, outdir + '/ink_capture_svgfile.svg')
#write the svgfile back to stdout for Inkscape
f_svg = open(svgfile, 'r')
for line in f_svg:
sys.stdout.write(line)
f_svg.close()
It turns out this was a useful exercise, because Inkscape did not pass the SVG document to my script on
standard in as I had expected. As I have now learned, Inkscape passes the path of a temporary file
containing the SVG document as the final argument to an effect script to avoid the complexities
of threading.
I also learned that it is much easier to debug extensions if you launch inkscape from the command line
because standard error messages from the scripts will be printed to the console.
Files: |
|||||||
![]() |
![]() |
||||||
| Home Compute Inkscape Contact | |||||||