This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz/purge_pointy_paths/purge_pointy_paths.py
2021-07-23 02:36:56 +02:00

49 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""
This filter deletes paths which render as point only
More usesless and/or redundant filters for removing duplicate nodes and segments are provided by the following extension:
- https://stadtfabrikanten.org/display/IFM/Purge+Duplicate+Path+Segments
- https://stadtfabrikanten.org/display/IFM/Purge+Duplicate+Path+Nodes
Extension for InkScape 1.X
Author: Mario Voigt / FabLab Chemnitz
Mail: mario.voigt@stadtfabrikanten.org
Date: 21.04.2021
Last patch: 21.04.2021
License: GNU GPL v3
"""
import inkex
from lxml import etree
class PurgePointyPaths(inkex.EffectExtension):
def effect(self):
if len(self.svg.selected) > 0:
for element in self.svg.selected.values():
if isinstance(element, inkex.PathElement):
p = element.path
commandsCoords = p.to_arrays()
# "m 45.250809,91.692739" - this path contains onyl one command - a single point
if len(commandsCoords) == 1:
element.delete()
# "m 45.250809,91.692739 z" - this path contains two commands, but only one coordinate.
# It's a single point, the path is closed by a Z command
elif len(commandsCoords) == 2 and commandsCoords[0][1] == commandsCoords[1][1]:
element.delete()
# "m 45.250809,91.692739 l 45.250809,91.692739" - this path contains two commands,
# but the first and second coordinate are the same. It will render as point
elif len(commandsCoords) == 2 and commandsCoords[-1][0] == 'Z':
element.delete()
# "m 45.250809,91.692739 l 45.250809,91.692739 z" - this path contains three commands,
# but the first and second coordinate are the same. It will render as point, the path is closed by a Z command
elif len(commandsCoords) == 3 and commandsCoords[0][1] == commandsCoords[1][1] and commandsCoords[2][1] == 'Z':
element.delete()
else:
inkex.errormsg('Please select some objects first.')
return
if __name__ == '__main__':
PurgePointyPaths().run()