Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding nodes to objects in Inkscape by Python script

This question is for someone with experience of Python coding of Inkscape extensions. Others need not waste their time, unless they really like a challenge!

I've written a Python extension that calculates the intersections between the line segments of different lines/polyline objects. I want to append new nodes to both objects at these intersection points (obviously in the correct node path order) but I have no idea how to approach this. The code in other extension scripts (e.g. "Modify Path\Add Nodes...") includes the use of node.set(), but I can't come close to figuring out how this is supposed to work. The script is available here if needed, but I don't see how that can help as there is no problem with it - it just produces intersection coordinates.

Grateful for any assistance.

like image 288
geotheory Avatar asked Jan 17 '13 15:01

geotheory


People also ask

How do I insert a node in Inkscape?

You can add nodes anywhere on a path by either double clicking or by Ctrl + Alt + click at the desired location. You can delete nodes with Del or Ctrl + Alt + click .

Can you script Inkscape?

Simple Inkscape Scripting makes it easy to automate repetitive drawing tasks. It defines a simple set of Python functions such as "rect" to draw a rectangle and "line" to draw a line.

Is Python needed for Inkscape?

The most common example of this is that the default Python version of the operating system is 3, but Inkscape requires Python2, resulting in all extensions giving an error.

How do I select multiple nodes in Inkscape?

Select Multiple NodesUse the Node tool to select a path. Click the first node. With the Shift key held down, continue clicking nodes until you have selected all the nodes you want. Inkscape highlights the selected nodes.


1 Answers

I know this is a long time ago, but I've just written a little extension that allows you to type in a couple lines of python, and iterate it over selected objects. It comes with code examples and pointers to documentation (cos the inkscape python modules aren't the best documented!).

Downside is, it crashes inkscape badly if your script returns malformed document. But it's good for quick hacks and testing code fragments.

  • http://smanohar.com/inkscape.php

Maybe this will be useful to other people too.

like image 81
Sanjay Manohar Avatar answered Oct 24 '22 06:10

Sanjay Manohar