Back in November last year I asked on the Inkscape Users mailing list and at InkscapeForum.com if there was a way in Inkscape to take a random mess of drawing objects, and restack them (or in other words, change the z-order ) in a specified direction. Specifically, I wanted to do this:
Well, the answer I got was that there was no way to do it...which started my quest to write an extension (plug-in) for Inkscape. If you just want to download, scroll to the bottom for the link, otherwise, read on for the whole story...
After extensive searching the web and posting on several lists, I found
this handy site and with the help of a few people on the Inkscape Users Mailing List, and lots from Kurt Hutchinson, who provided some example extensions, I wrestled with figuring out python, and got a working extension. It was horribly slow due to a limitation of version .45 Inkscape, but it worked.
After spreading word of my success and complaining about the performance, not much happened. A few people liked the extension and some of the Inkscape developers thought it would have some value for other users. Then I upgraded from the stable Inkscape .45 to the developers .46 versions. And it broke.
Once again, the search began, and I eventually found out that the XML parser in Inkscape was changes, which broke my little extension. Fortunately, at the same time, an addition was made to Inkscape that allowed my extension to speed up hugely. (Thanks, Terry Brown!) Previously, I had to spawn a new instance of Inkscape to get the bounding boxes of each object. The new patch let me get all of them in one call! Also, enhancements were made to the extension dialogs to allow option groups (buttons) whick let me increase the functionality of the extension!
Now a user could select the direction to restacl in (left to right, right to left, top to bottom, or bottom to top as well as the point to compare on each object. See the dialog grab for the options. Of course, using the option buttons exposed a new bug in Inkscape regarding the live update. I have submitted a bug report, and hopefully it will be fixed before the final .46 release.
Terry Brown helped again, cleaning up my python, and introducing me to the wonder of the python dictionary. Again, I left it for a while, and eventiallu came up with the idea to order by an arbitrary angle (after figuring out the python match functions) and from there it was a quick jaunt to also adding radial ordering. Off to the right is an example of these three options.
So the whole thing is done (for now) and posted over in the Inkscape Bug-tracker as a wishlist option. Hopefully it will make it in a future release of Inkscape! If not, you can download it yourself here and instal it by unsipping the two files into your Inkscape instalation\share\extensions directory.
And here is one final example of what it can do. I started with an image of an explosion then created an array of tiles clones of random star shapes over it. I randomized the overlap and rotation as well. Tile clones orders the clones in a column/row fashion, but running the restack extension (radial inward) gave me this: