Get element by id in Inkscape
If you’re automating the change of an Inkscape image, you often will know the Id of the element(s) you want to change.
Normally in XML, you would get the root node and use getElementById on that node. Apparently that’s not how Python does things, so Inkscape adds a getElementById method to the inkex.Effect class.
[toggle code]
-
class DuplicateMultiple(inkex.Effect):
- …
-
def effect(self):
- #get the logo
- logo = self.getElementById('hoboLogo')
- #do stuff to the logo
- …
You can use “set” to set the style, transform, or other attributes of the Inkscape object, or anything else you would normally do to a selected node in your Inkscape effect.
More Inkscape
- Updated Inkscape extension
- Inkscape extensions on Mac OS X are a little easier in the latest versions.
- Using the color picker in Inkscape extensions
- It was pretty easy, looking at the built-in extensions, to switch colors from one to another if I wanted to type their values by hand. But using the color parameter type took a bit of sleuthing.
- Write an Inkscape extension: create multiple duplicates
- Once you get past the complete lack of simple real-world examples, it’s pretty easy to make Inkscape extensions. So, here’s a simple real-world example.
I have been googling everywhere for some method of controlling the order in which, say a selected bunch of paths are fed to the extension - or even just trying to find out what determines the order. I started an extension as a hack mostly - learning as I go, and not brilliant with python but I have everything working except I need to somehow sort the order in which each path is processed, by the extension. This is the closest I have found to the information I am seeking. I thought perhaps a sort routine by item id or label, or if I could sort by order of selection order. The order of the original SVG file, item id, label, all seem to have no effect on what seems like a totally random ordering of paths sent to the extension.
crosseyed at 1:12 a.m. May 15th, 2010
amkoc