https://wiki.inkscape.org/wiki/index.php?title=Generating_objects_from_extensions&feed=atom&action=historyGenerating objects from extensions - Revision history2024-03-29T02:19:37ZRevision history for this page on the wikiMediaWiki 1.36.1https://wiki.inkscape.org/wiki/index.php?title=Generating_objects_from_extensions&diff=122086&oldid=prevMoini at 19:56, 3 February 20232023-02-03T19:56:03Z<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 19:56, 3 February 2023</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>{{<del style="font-weight: bold; text-decoration: none;">outdated</del>}}</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>{{<ins style="font-weight: bold; text-decoration: none;">Template:MovedToOtherSite|topic=Extension development|new_url=https://inkscape.gitlab.io/extensions/documentation/|new_site=GitLab</ins>}}</div></td></tr>
<tr><td colspan="2"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td colspan="2"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">----</ins></div></td></tr>
<tr><td colspan="2"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you need an extension to generate an object in Inkscape, there are many tools that already exist to help you. <tt>inkex.py</tt> is the most notable, as this provides the routines to insert the SVG element into the XML tree of the SVG document, for more info on these is available at [[Python modules for extensions]].</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you need an extension to generate an object in Inkscape, there are many tools that already exist to help you. <tt>inkex.py</tt> is the most notable, as this provides the routines to insert the SVG element into the XML tree of the SVG document, for more info on these is available at [[Python modules for extensions]].</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
</table>Moinihttps://wiki.inkscape.org/wiki/index.php?title=Generating_objects_from_extensions&diff=120978&oldid=prevPulsar17: Mark page as outdated.2022-03-10T21:33:38Z<p>Mark page as outdated.</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 21:33, 10 March 2022</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td colspan="2"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">{{outdated}}</ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you need an extension to generate an object in Inkscape, there are many tools that already exist to help you. <tt>inkex.py</tt> is the most notable, as this provides the routines to insert the SVG element into the XML tree of the SVG document, for more info on these is available at [[Python modules for extensions]].</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If you need an extension to generate an object in Inkscape, there are many tools that already exist to help you. <tt>inkex.py</tt> is the most notable, as this provides the routines to insert the SVG element into the XML tree of the SVG document, for more info on these is available at [[Python modules for extensions]].</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l115">Line 115:</td>
<td colspan="2" class="diff-lineno">Line 116:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If in doubt about the right attribute name and format, just check a similar object in the XML viewer in Inkscape.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>If in doubt about the right attribute name and format, just check a similar object in the XML viewer in Inkscape.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>===Line Segment===</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>===Line Segment ===</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Paths can be quite tricky to get the hang of if you don't know the meaning of the letters. Read the SVG specification for a full list.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Paths can be quite tricky to get the hang of if you don't know the meaning of the letters. Read the SVG specification for a full list.</div></td></tr>
</table>Pulsar17https://wiki.inkscape.org/wiki/index.php?title=Generating_objects_from_extensions&diff=107346&oldid=prevMatyilona: Adding link to Python modules for extensions2017-11-06T20:56:52Z<p>Adding link to Python modules for extensions</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 20:56, 6 November 2017</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>If you need an extension to generate an object in Inkscape, there are many tools that already exist to help you. <tt>inkex.py</tt> is the most notable, as this provides the routines to insert the SVG element into the XML tree of the SVG document.</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>If you need an extension to generate an object in Inkscape, there are many tools that already exist to help you. <tt>inkex.py</tt> is the most notable, as this provides the routines to insert the SVG element into the XML tree of the SVG document<ins style="font-weight: bold; text-decoration: none;">, for more info on these is available at [[Python modules for extensions]]</ins>.</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>There is currently no universal set of tools to allow a single function to be called, because different extension have different attibutes for thir objects. For example, the barcode extension merely needs a black rectangle with no stroke, but another may need a way to set the stroke width, dashes and opacity. Thus, it is often best to write your own subroutine for generating your objects.</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>There is currently no universal set of tools to allow a single function to be called, because different extension have different attibutes for thir objects. For example, the barcode extension merely needs a black rectangle with no stroke, but another may need a way to set the stroke width, dashes and opacity. Thus, it is often best to write your own subroutine for generating your objects.</div></td></tr>
</table>Matyilonahttps://wiki.inkscape.org/wiki/index.php?title=Generating_objects_from_extensions&diff=87272&oldid=prev~suv: fix incorrect SVG stroke style property ('width' -> 'stroke-width')2012-11-25T15:42:48Z<p>fix incorrect SVG stroke style property ('width' -> 'stroke-width')</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:42, 25 November 2012</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l10">Line 10:</td>
<td colspan="2" class="diff-lineno">Line 10:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> style = { 'stroke' : 'none',</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> style = { 'stroke' : 'none',</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> 'width' <del style="font-weight: bold; text-decoration: none;"> </del>: '1',</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> '<ins style="font-weight: bold; text-decoration: none;">stroke-</ins>width' <ins style="font-weight: bold; text-decoration: none;"> </ins>: '1',</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> 'fill' : '#000000'</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> 'fill' : '#000000'</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> }</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> }</div></td></tr>
<tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l94">Line 94:</td>
<td colspan="2" class="diff-lineno">Line 94:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> style = { 'stroke' : '#000000',</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> style = { 'stroke' : '#000000',</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> 'width' <del style="font-weight: bold; text-decoration: none;"> </del>: '1',</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> '<ins style="font-weight: bold; text-decoration: none;">stroke-</ins>width' <ins style="font-weight: bold; text-decoration: none;"> </ins>: '1',</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> 'fill' : 'none' }</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> 'fill' : 'none' }</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> ell_attribs = {'style':simplestyle.formatStyle(style),</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> ell_attribs = {'style':simplestyle.formatStyle(style),</div></td></tr>
</table>~suvhttps://wiki.inkscape.org/wiki/index.php?title=Generating_objects_from_extensions&diff=65617&oldid=prevFlor: /* Line Segment */2010-11-02T08:54:07Z<p><span dir="auto"><span class="autocomment">Line Segment</span></span></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 08:54, 2 November 2010</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l135">Line 135:</td>
<td colspan="2" class="diff-lineno">Line 135:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> line = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> line = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></nowiki></pre></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div></nowiki></pre></div></td></tr>
<tr><td colspan="2"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category:Developer Documentation]]</ins></div></td></tr>
<tr><td colspan="2"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">[[Category:Extensions]]</ins></div></td></tr>
</table>Florhttps://wiki.inkscape.org/wiki/index.php?title=Generating_objects_from_extensions&diff=65113&oldid=prev~suv: /* A simple example */ typo2010-10-13T20:04:24Z<p><span dir="auto"><span class="autocomment">A simple example: </span> typo</span></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 20:04, 13 October 2010</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l4">Line 4:</td>
<td colspan="2" class="diff-lineno">Line 4:</td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==A simple example==</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>==A simple example==</div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>Let's look at a simple Python <del style="font-weight: bold; text-decoration: none;">fuunction </del>for drawing a black rectangle:</div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>Let's look at a simple Python <ins style="font-weight: bold; text-decoration: none;">function </ins>for drawing a black rectangle:</div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div><pre></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>#SVG element generation routine</div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>#SVG element generation routine</div></td></tr>
</table>~suvhttps://wiki.inkscape.org/wiki/index.php?title=Generating_objects_from_extensions&diff=54707&oldid=prevInductiveload: Created page with 'If you need an extension to generate an object in Inkscape, there are many tools that already exist to help you. <tt>inkex.py</tt> is the most notable, as this provides the routi...'2009-11-06T18:55:03Z<p>Created page with 'If you need an extension to generate an object in Inkscape, there are many tools that already exist to help you. <tt>inkex.py</tt> is the most notable, as this provides the routi...'</p>
<p><b>New page</b></p><div>If you need an extension to generate an object in Inkscape, there are many tools that already exist to help you. <tt>inkex.py</tt> is the most notable, as this provides the routines to insert the SVG element into the XML tree of the SVG document.<br />
<br />
There is currently no universal set of tools to allow a single function to be called, because different extension have different attibutes for thir objects. For example, the barcode extension merely needs a black rectangle with no stroke, but another may need a way to set the stroke width, dashes and opacity. Thus, it is often best to write your own subroutine for generating your objects.<br />
<br />
==A simple example==<br />
Let's look at a simple Python fuunction for drawing a black rectangle:<br />
<pre><br />
#SVG element generation routine<br />
def draw_SVG_square((w,h), (x,y), parent):<br />
<br />
style = { 'stroke' : 'none',<br />
'width' : '1',<br />
'fill' : '#000000'<br />
}<br />
<br />
attribs = {<br />
'style' : simplestyle.formatStyle(style),<br />
'height' : str(h),<br />
'width' : str(w),<br />
'x' : str(x),<br />
'y' : str(y)<br />
}<br />
circ = inkex.etree.SubElement(parent, inkex.addNS('rect','svg'), attribs )<br />
</pre><br />
<br />
The first thing to notice is that all the attributes of the object are stored in a dictionary format, with everything being a string. This means you have to convert all your parameters to strings if appropriate (like the <tt>height</tt> and <tt>width</tt> attributes).<br />
<br />
Next, all the style attributes (colours, widths, fonts, etc) are put together in SVG under <tt>style</tt>. To generate this string, there exists a helper function <tt>simplestyle.formatStyle()</tt>. You simply feed this function a dictionary of the styles you want, just like the attributes. You can then use this directly as the style attribute.<br />
<br />
The next thing to see is how to add the element to the XML tree. <tt>inkex.py</tt> has the function to do this using the LXML parser. 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.<br />
<br />
The type of the object is in the <tt>svg</tt> namespace, which means it begins <tt>svg:</tt> (for a rectangle, it is <tt>svg:rect</tt>). LXML cannot parse colons, so we use the <tt>inkex.addNS</tt> to prepend the namespace.<br />
<br />
The attributes of the object just needs to be passed the dictionary <tt>attribs</tt> we made earlier.<br />
<br />
The "parent" of the object is the containing element. This is usually a group or a layer. This will be passed in by the calling function, and we will see it in action later.<br />
<br />
When this function is run with the right parameters, the rectangle will be added to the SVG document.<br />
<br />
==Getting the parent==<br />
<br />
Finding the parent is easy: you can just pass in the current layer from the <tt>self</tt> object if you like:<br />
<pre><nowiki><br />
parent = self.current_layer<br />
draw_SVG_square((1,1), (0,0), parent)<br />
</nowiki></pre><br />
<br />
This will just plonk the rectangle into the document, centred on the origin.<br />
<br />
Alternatively, you can create a group much like any other object:<br />
<pre><nowiki><br />
centre = self.view_center #Put in in the centre of the current view<br />
grp_transform = 'translate' + str( centre )<br />
<br />
grp_name = 'Group Name'<br />
grp_attribs = {inkex.addNS('label','inkscape'):grp_name,<br />
'transform':grp_transform }<br />
grp = inkex.etree.SubElement(self.current_layer, 'g', grp_attribs)#the group to put everything in<br />
</nowiki></pre><br />
<br />
By the way, any object can be assigned a name as we did there, which is often helpful when generating many objects:<br />
<br />
<pre><nowiki><br />
inkex.addNS('label','inkscape') : name<br />
</nowiki></pre><br />
<br />
By setting the transform as <tt>self.view_center</tt>, we made sure the origin of the group is in the centre of the current view of the document. We will come back to transforms later.<br />
<br />
The <tt>grp</tt> object can now be used as a parent for the rectangle:<br />
<pre><nowiki><br />
draw_SVG_square((1,1), (0,0), grp)<br />
</nowiki></pre><br />
This will draw a 1×1 black square in the center of the view.<br />
<br />
==Transforms==<br />
<br />
It is easy to transform an object: just supply a string like the folllowing as the <tt>transform</tt> attribute of the element:<br />
*<tt>trans = 'translate(10,10)'</tt><br />
*<tt>trans = 'translate(10,10) rotate(10)'</tt><br />
*<tt>trans = 'skewX(-1)'</tt><br />
<br />
Available commands: <tt>translate, scale, rotate, skewX, skewY, matrix</tt>. The transforms are composed in left-right order (i.e. the translate comes first in the second example).<br />
<br />
==More Examples==<br />
<br />
===Ellipses===<br />
<br />
Ellipses are actually path elements, but Inkscape generates the nodes automatically if you feed it the correct attributes in the Sodipodi namespace. The vital ones are <tt>rx, ry, cx, cy</tt>.<br />
<br />
Ellipses require some attributes in the <tt>sodipodi:</tt> namespace, so we also use the <tt>addNS()</tt> function in the attribute dictionary:<br />
<br />
<pre><nowiki><br />
def draw_SVG_ellipse((rx, ry), (cx, cy), parent, start_end=0,2*pi),transform='' ):<br />
<br />
style = { 'stroke' : '#000000',<br />
'width' : '1',<br />
'fill' : 'none' }<br />
ell_attribs = {'style':simplestyle.formatStyle(style),<br />
inkex.addNS('cx','sodipodi') :str(cx),<br />
inkex.addNS('cy','sodipodi') :str(cy),<br />
inkex.addNS('rx','sodipodi') :str(rx),<br />
inkex.addNS('ry','sodipodi') :str(ry),<br />
inkex.addNS('start','sodipodi') :str(start_end[0]),<br />
inkex.addNS('end','sodipodi') :str(start_end[1]),<br />
inkex.addNS('open','sodipodi') :'true', #all ellipse sectors we will draw are open<br />
inkex.addNS('type','sodipodi') :'arc',<br />
'transform' :transform<br />
<br />
}<br />
ell = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), ell_attribs )<br />
</nowiki></pre><br />
<br />
This will draw an open arc, with a black stroke of width 1 and no fill. The transform here can be passed in from outside.<br />
<br />
If in doubt about the right attribute name and format, just check a similar object in the XML viewer in Inkscape.<br />
<br />
===Line Segment===<br />
<br />
Paths can be quite tricky to get the hang of if you don't know the meaning of the letters. Read the SVG specification for a full list.<br />
<br />
Here, the style information has been passed in from outside the function.<br />
<br />
<pre><nowiki><br />
#draw an SVG line segment between the given (raw) points<br />
def draw_SVG_line( (x1, y1), (x2, y2), style, name, parent):<br />
line_style = { 'stroke': style.l_col,<br />
'stroke-width':str(style.l_th),<br />
'fill': style.l_fill<br />
}<br />
<br />
line_attribs = {'style' : simplestyle.formatStyle(line_style),<br />
inkex.addNS('label','inkscape') : name,<br />
'd' : 'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)}<br />
<br />
line = inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )<br />
</nowiki></pre></div>Inductiveload