Appending new nodes by python

Discussion about writing code for Inkscape.
User avatar
geotheory
Posts: 11
Joined: Wed Jan 09, 2013 9:23 pm
Location: London, UK

Appending new nodes by python

Postby geotheory » Tue Jan 15, 2013 11:25 pm

I'm working on a script to calculate if selected line objects intersect (and if so where), and to create new nodes in both objects at the intersection point. I'm about half way through the script, and can extract node info and process it to check for intersections. But being fairly new to Inkscape I have no idea how to create new nodes within a specific object (at a specific path position, etc). Grateful for any pointers. If it helps, the script acquires the selection node data via the probably fairly typical:

Code: Select all

import inkex
import sys

class TemplateEffect(inkex.Effect):
   def __init__(self):
      inkex.Effect.__init__(self)
   def effect(self):
      for id, node in self.selected.iteritems():
         # CODE...


Seperately, the documentation here (http://wiki.inkscape.org/wiki/index.php ... extensions) seems a bit light on detail. Is there a better resource anywhere with a list of python functionality, or better still a collection of basic examples?

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Appending new nodes by python

Postby brynn » Wed Jan 16, 2013 6:59 pm

Creating new nodes precisely at path intersections would be extremely useful! Imo, it should be a built-in option for the Node tool. But I would take it any way it comes, even via extension!

User avatar
geotheory
Posts: 11
Joined: Wed Jan 09, 2013 9:23 pm
Location: London, UK

Re: Appending new nodes by python

Postby geotheory » Wed Jan 16, 2013 11:36 pm

Well I've done a script to calculate and report on intersections - available at https://dl.dropbox.com/u/46043231/apps/ ... tNodes.zip

To run it needs to be unzipped into the ..Inkscape/share/extensions folder, and will appear as 'AddIntersectNodes' in the 'Modify Path' submenu. It calculates intersections for straight (unbeziered) simple lines or polylines that have been selected using the node tool, but not yet with all closed-path objects (polygons). It doesn't yet calculate if/where polylines intersect with themselves, but I might add this. You'll need to set SVG output preferences to not allow relative coordinates before you start the new document, or copy paste already relatively-encoded objects into a new doc with this setting before you start.

If anyone can help by contributing or advising me on functionality to add nodes at intersection points that would be great.


Return to “Programming”