This will just plonk the rectangle into the document, centred on the origin.Īlternatively, you can create a group much like any other object:Ĭentre = self. When this function is run with the right parameters, the rectangle will be added to the SVG document.įinding the parent is easy: you can just pass in the current layer from the self object if you like: This will be passed in by the calling function, and we will see it in action later. The "parent" of the object is the containing element. The attributes of the object just needs to be passed the dictionary attribs we made earlier. LXML cannot parse colons, so we use the inkex.addNS to prepend the namespace. The type of the object is in the svg namespace, which means it begins svg: (for a rectangle, it is svg:rect). This needs to be given the "parent" of the object (we'll come back to this), the "type" of the object, and the attributes of the object. inkex.py has the function to do this using the LXML parser. The next thing to see is how to add the element to the XML tree. You can then use this directly as the style attribute. You simply feed this function a dictionary of the styles you want, just like the attributes. To generate this string, there exists a helper function simplestyle.formatStyle(). Next, all the style attributes (colours, widths, fonts, etc) are put together in SVG under style. This means you have to convert all your parameters to strings if appropriate (like the height and width attributes). It doesnt give instructions to the machine (such as stitch length or fabric type), which is where. There already is an extension which will prepare files for embroidery machines. But I have no idea when it might be available in Inkscape. The first thing to notice is that all the attributes of the object are stored in a dictionary format, with everything being a string. There is a developer working on an Inkscape embroidery extension. 'style' : simplestyle.formatStyle(style),Ĭirc = (parent, inkex.addNS('rect','svg'), attribs ) Let's look at a simple Python function for drawing a black rectangle:ĭef draw_SVG_square((w,h), (x,y), parent):
0 Comments
Leave a Reply. |