I created a low poly portrait in Inkscape that I want to recreate in a physical medium. Is there a programmatic way to label individual polygon objects in an incremental fashion (1,2,3...n)? If Inkscape can't do it, is there another vector editor that can?

I have over 100 triangles and I would rather not do this manually.

  • Are you trying to make it physically flat or 3D? maybe you should add that to your question? Dec 14 '17 at 21:02
  • the poly portrait is 2D polygons. Trying to figure out best/easiest way to label each polygon with its own number so I can keep track of pieces when I print out the image. Dec 14 '17 at 21:09
  • I tried to copy such a raster, which is a lot of triangles, to a new sheet, combine them. Then made a new copy of that and with extensions, numerate path, I got all the dots with numbers. Unfortunately, at each point multiple triangles meet, and you get overlapping labels for each triangle at that point. So I deleted every third label and renumbered them with a script, but the numbers are only somehow close to the polygons, so you have to adjust them yourself, and then you have to search for them. I gueess it is more easy to generate your number and distribute them evenly over a page, ... Dec 16 '17 at 14:10
  • …with a script, then adjust them by hand, but without typing every number and searching for each. Dec 16 '17 at 14:11

The short answer is yes.

The longer answer is you need to go outside of Inkscape if you want automation.

If you use Inkscape's own XML editor ( Edit -> XML Editor) you can see how Inkscape documents are structured.

If you've used paths or the circle tool to create an object they will show up as "svg:path id path12345", or "svg:rect id12345" if you've used the rectangle tool.

Unless you've manually named them, none of your objects will have the property "svg:inkscape label" set, or in other words, doing that programmatically, is essentially what you're wanting to do.

Choose a programming language that your are comfortable with and then have it loop over the .svg file looking for object definitions and setting (adding to the object properties to be saved in the SVG) the inkscape:label property as the value of an incrementing variable and output the result to a file.

Though if by label you mean make a text object and include that in a file, this wiki page shows how to use Python to make a "Hello World" Inkscape document us - creating a new layer then adding a text object which should give you pointers on how to create a text object, create the actual text message, position the resulting object, and then group it with the triangle it relates to.

Inkscape comes complete with several libraries written in python that allow you to script object handling amongst other things. And, if you find yourself wanting to repeat the same task on another project, you might want to consider making an Inkscape extension

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.