Added Convert To Polylines and fixed some description in Contour Scanner

This commit is contained in:
Mario Voigt 2020-09-05 03:20:23 +02:00
parent 4b009f75e8
commit 8003f7f11b
3 changed files with 65 additions and 1 deletions

View File

@ -4,7 +4,6 @@
<id>fablabchemnitz.de.contour_scanner</id>
<param name="main_tabs" type="notebook">
<page name="tab_active" gui-text="Active">
<label>This tool helps you to find nasty contours which might bug you and prevent your work from being ready for production. You can find the complete documentation at the Wiki space of https://fablabchemnitz.de</label>
<label appearance="header">General</label>
<param name="breakapart" type="bool" gui-text="Break apart selection into single contours" gui-description="(with ignoring the group hirarchy by taking all children elements)">false</param>
<param name="removefillsetstroke" type="bool" gui-text="Remove fill and define stroke">false</param>
@ -33,6 +32,8 @@
<label>you found a bug or got some fresh code? Just report to mario.voigt@stadtfabrikanten.org. Thanks!</label>
<label appearance="url">https://fablabchemnitz.de</label>
<label>License: GNU GPL v3</label>
<separator/>
<label>This tool helps you to find nasty contours which might bug you and prevent your work from being ready for production. Ideally you should convert your paths to polylines because the algorithm used by Contour Scanner is not able to distinguish between curves and polylines. It will handle curves like polylines but that creates visual and measurable errors. Either use "Split Bezier (Subdivide Path)" or "Add Nodes" extension to split into smaller segments which makes more precise. You can also run "Flatten Bezier" to make smooth polylines. For roughest approximation use "Convert to Polylines" extension to create real polylines. You can find the complete documentation at the Wiki space of https://fablabchemnitz.de</label>
</page>
</param>
<effect>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Convert To Polylines</name>
<id>fablabchemnitz.de.convert_polylines</id>
<effect>
<object-type>path</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz">
<submenu name="Modify existing Path(s)"/>
</submenu>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">convert_polylines.py</command>
</script>
</inkscape-extension>

View File

@ -0,0 +1,47 @@
#!/usr/bin/env python3
"""
Extension for InkScape 1.0
Converts curves to polylines - a quick and dirty helper for a lot of elements. Basically the same functionality can be done with default UI featureset but with a lot more mouse clicks
Author: Mario Voigt / FabLab Chemnitz
Mail: mario.voigt@stadtfabrikanten.org
Date: 05.09.2020
Last patch: 05.09.2020
License: GNU GPL v3
"""
import inkex
from inkex.paths import Path
class ConvertToPolylines(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
def convertPath(self, node):
if node.tag == inkex.addNS('path','svg'):
polypath = []
i = 0
for x, y in node.path.end_points:
if i == 0:
polypath.append(['M', [x,y]])
else:
polypath.append(['L', [x,y]])
i += 1
node.set('d', str(Path(polypath)))
children = node.getchildren()
if children is not None:
for child in children:
self.convertPath(child)
def effect(self):
if len(self.svg.selected) == 0:
self.convertPath(self.document.getroot())
else:
for id, item in self.svg.selected.items():
self.convertPath(item)
if __name__ == '__main__':
ConvertToPolylines().run()