Best way to write complex script

Discussion about writing code for Inkscape.
rengels
Posts: 2
Joined: Mon Jan 16, 2012 6:52 am

Best way to write complex script

Postby rengels » Mon Jan 16, 2012 7:27 am

Hi,

I want to write a script that helps me generating 3-View plans for model airplanes and ships and convert them to line paths suitable for a CNC foam cutter.
The script would preferably:
Check front view cuts against side and top view and automatically adjust the sizes.
Generate missing cut lines by interpolating neighbouring ones or generate them from different views.
Calculate cut paths from lines, add space for burn off and add lead in and lead out paths.

So the script will probably need to:
- Interpolate curves
- Do Path operations like "intersect" and "object to path"
- cut copy paste
- determine size of paths

After having looked into python extension it seems that they only work on the SVG DOM tree.
So e.g. the stroke script for the egg-bot is a very complex thing, as are some of the other scripts.

I was thinking about different possibilities and would like to hear an expert opinion which of them might be the best.

1. using py2geom
problem: couldn't find example scripts and the lib2geom svn tree does not compile out of the box

2. write the extension in cpp and patch it into inkscape itself
problem: not stand alone and the patch would probably never get into mainline

3. use inkscape dbus interface
problem: possibly missing functionality. Copyright entries are quite old so it's probably not maintained

4. use inkex
problem: possibly a lot of functionality that needs to be re-implemented

5. not use Inkscape at all but some other SW package
problem: I haven't found a scriptable SVG graphics package nor scriptable SVG editor

What would the experts propose?

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Best way to write complex script

Postby ~suv » Mon Jan 16, 2012 1:49 pm

Off topic:
rengels wrote:1. using py2geom
problem: couldn't find example scripts and the lib2geom svn tree does not compile out of the box

SVN? The current source repository of lib2geom is using bazaar, hosted at launchpad.net: lp:lib2geom
According to this recent mail (2011-12-30) by one of the developers, py2geom does compile (at least on Windows). (I never tried myself).

rengels wrote:3. use inkscape dbus interface
problem: possibly missing functionality. Copyright entries are quite old so it's probably not maintained

Quite old? There doesn't even exist a stable release of Inkscape yet which includes the dbus scripting API: it is based on a GSoC project from 2009, and so far has only been merged in the development branch (lp:inkscape) - after the initial release of Inkscape 0.48. It is not enabled by default when configuring for building - see 'configure --help' for the options.
The more important issue is most likely to get scripting via dbus to work equally well on all supported platforms out-of-the-box. I'm not aware of existing packaging solutions for the Windows and Mac OS X ports of Inkscape.

rengels
Posts: 2
Joined: Mon Jan 16, 2012 6:52 am

Re: Best way to write complex script

Postby rengels » Mon Jan 23, 2012 3:34 am

Short update:

I am currently drilling into lib2geom.
Two changes enable the bazar lib2geom version to compile again with gcc.
The sourceforge page seems to be outdated and pointing to an abandoned repository.
The lib2geom toys are cool. Especially the convolute gears.

py2geom examples are also working, but seems to cover only a tiny part of the lib2geom.

I am now making some trials with lib2geom and inkscape plugins.
Possibly without python as I am getting angry when I see code like this:

Code: Select all

def pointdistance((x1,y1),(x2,y2)):
    return math.sqrt(((x2 - x1) ** 2) + ((y2 - y1) ** 2))
def bezlenapprx(sp1, sp2):
    return pointdistance(sp1[1], sp1[2]) + pointdistance(sp1[2], sp2[0]) + pointdistance(sp2[0], sp2[1])


Argh. What types are involved here? How would I know that sp1 is an array? Isn't there a point distance operator somewhere? lib2geom already has functions to calculate the length of a bezier.

I will keep you infomed.


Return to “Programming”