Date: Mon, 16 Jan 2012 10:24:00 +0100 From: Jasper van de Gronde <th.v.d.gronde@...528...> Subject: Re: [Inkscape-devel] Writing an extension To: inkscape-devel@lists.sourceforge.net
On 13-01-12 19:10, Trever L. Adams wrote:
This relates to https://bugs.launchpad.net/inkscape/+bug/247463 and comment 37 in particular.
I would like to be able to attach information to objects that are needed for high quality digitization. This includes stitch length and stitch direction. I am thinking of displaying the direction as gradient, although direction may be very complex. I am just learning about SVG so, I do not know if there are smart ways of doing this. (For example, think of a leaf, where you may have 20 different direction changes.) I also do not know XML very well (creating schema, etc).
So basically you want to embed information needed to convert a drawing to something that can be embroidered? And you want this information to be visible and manipulable in Inkscape's interface?
Yes, I am starting from information I have found here: http://jumpnslide.tumblr.com/post/2557920924/how-to-use-inkscape-as-a-game-d...
I am missing just a few pieces of information:
1) How do I set values in the interface (fetch them from the SVG)? I have defaults working, etc. 2) How do I insert my custom attributes back into the SVG?
The following partial code block doesn't do #2 properly and actually crashes inkscape:
#Loop through all the selected items in Inkscape for id, node in self.selected.iteritems():
#Check if the node is a Group ( "svg:g" tag in XML ) if node.tag == inkex.addNS('g','svg'): #DO SOME THINGS TO GROUPS outputBlock += "Found a Group!" + "\n" children = list(node) for node2 in children: outputBlock += "Group " + str(node) + " contains: " + str(node2.attrib["id"]) + "\n" node2.attrib["max_stitch_length"] = str(max_stitch_length)
I am sure I am going to have to create an XML schema right? If so can you point me in the right direction?
So, is there a standard way to extend SVG or embed such codes in SVG for a given object?
Extending SVG is in principle very easy, just define a namespace that hasn't been taken yet (and preferably as specific as possible) and use elements/attributes from that namespace. Ideally you would also create a schema to define which elements/attributes are in that namespace and so on, but I wouldn't necessarily start out that way (although it's obviously a good idea to think about a formal definition if you want this to be used by others as well, and/or save yourself some trouble in the future).
The idea is that viewers/editors will ignore anything they don't recognize. The extent to which this is true in practice varies a bit, and it's definitely not a given that an editor (Inkscape) will preserve the tags, but in principle it should "work" (in the sense that nothing will suddenly go wrong).
Can you provide me with any urls which show an example of how to create an XML schema? In the past when I have looked, I just walk away with a headache.
I would like to do this in SVG and Inkscape since I believe both are scriptable and both can be used for print as well. (This is a project for both print and embroidery.)
Inkscape itself is not really scriptable. What you can do is write a python extension that essentially gets a piece of SVG to transform. But this is fairly flexible. Also, if you know C/C++ you might be able to write something like an LPE to help out.
LPE? I do know several languages, including C/C++.
I thought Inkscape was. I would like to be able to change colors (and maybe remove them in some cases), resize and place objects and save/load files from scripts.
Additional request for information: Is it possible to define a custom color table? Embroidery machines usually have a fixed color table (which can be converted to various thread vendor product/color numbers).
Not sure, but I think there is at least some support for color management. Perhaps someone else knows more about this?
I think the palettes was what I was looking for and have since learned how to do this.
Is it possible to turn an outline on for an object and give it a different color than the object, or easily create an outline?
You mean outline as in stroke? If so, that's trivial in SVG, every object intrinsically has a fill and a stroke.
Yes, I finally figured this out. As I said, new to inkscape and SVG.
Finally, is there a way to do "Ungroup repeatedly until there are no groups left, and convert objects to paths." as part of an extension (http://www.jonh.net/~jonh/inkscape-embroidery/) without modifying the original (as part of an export, etc.)?
I think it's possible to create extensions for output as well, so conceivably this would be possible. In any case, you might want to have a look at this extension:
https://gitorious.org/various-small-stuff/inkscape-ungroup-deep/
I am starting to wonder if I actually need this, but on having looked at that code, I was able to at least start working on groups with my code.
Thank you, Trever