From 207ae044fe4b11d2021354f2ec057b1a62c37749 Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Tue, 19 Oct 2021 14:06:22 +0200 Subject: [PATCH] added duplicate,reverse,join --- .../duplicate_reverse_join.inx | 15 +++++ .../duplicate_reverse_join.py | 63 +++++++++++++++++++ .../duplicate_reverse_join/meta.json | 20 ++++++ 3 files changed, 98 insertions(+) create mode 100644 extensions/fablabchemnitz/duplicate_reverse_join/duplicate_reverse_join.inx create mode 100644 extensions/fablabchemnitz/duplicate_reverse_join/duplicate_reverse_join.py create mode 100644 extensions/fablabchemnitz/duplicate_reverse_join/meta.json diff --git a/extensions/fablabchemnitz/duplicate_reverse_join/duplicate_reverse_join.inx b/extensions/fablabchemnitz/duplicate_reverse_join/duplicate_reverse_join.inx new file mode 100644 index 00000000..af0f065e --- /dev/null +++ b/extensions/fablabchemnitz/duplicate_reverse_join/duplicate_reverse_join.inx @@ -0,0 +1,15 @@ + + + Duplicate + Reverse + Join + fablabchemnitz.de.duplicate_reverse_join + + + + + + + + + \ No newline at end of file diff --git a/extensions/fablabchemnitz/duplicate_reverse_join/duplicate_reverse_join.py b/extensions/fablabchemnitz/duplicate_reverse_join/duplicate_reverse_join.py new file mode 100644 index 00000000..56fbc77c --- /dev/null +++ b/extensions/fablabchemnitz/duplicate_reverse_join/duplicate_reverse_join.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 Ellen Wasboe, ellen@wasbo.net +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +""" +Duplicate subpaths of all selected paths, reverse and join end nodes. +""" + +import inkex + +class DuplicateReverseJoin(inkex.EffectExtension): + + def effect(self): + for elem in self.svg.selection: + + pp=elem.path.to_absolute() + dList=str(pp).split(' M') + dFinal='' + l=0 + for sub in dList: + if l>0: + origSub='M'+dList[l] + else: + origSub=dList[l] + + elem.path=origSub + reSub=elem.path.reverse() + + if l>0: + origSub=' '+origSub + + if origSub.find('Z') > -1: + dRev=str(reSub).split(' ') + strRev='' + if dRev[3]=='L' and dRev[1]==dRev[4] and dRev[2]==dRev[5]: + strRev=' '.join(dRev[0:3])+' '+' '.join(dRev[6:]) #avoid that reverse path duplicate first node + else: + strRev=' '.join(dRev) + dFinal=dFinal+origSub+' '+strRev #keep original and reverse as separate closed paths + if dRev[-1]!='Z': + dFinal=dFinal+' Z'#avoid that reverse of closed path is open + else: + dRev=str(reSub).split(' ') + dFinal=dFinal+origSub+' '+' '.join(dRev[3:])+' Z' #pop off M element of reverse path and add Z to close + l+=1 + elem.path=dFinal + + +if __name__ == '__main__': + DuplicateReverseJoin().run() \ No newline at end of file diff --git a/extensions/fablabchemnitz/duplicate_reverse_join/meta.json b/extensions/fablabchemnitz/duplicate_reverse_join/meta.json new file mode 100644 index 00000000..9ebc2eae --- /dev/null +++ b/extensions/fablabchemnitz/duplicate_reverse_join/meta.json @@ -0,0 +1,20 @@ +[ + { + "name": "Duplicate + Reverse + Join", + "id": "fablabchemnitz.de.duplicate_reverse_join", + "path": "duplicate_reverse_join", + "original_name": "Duplicate, reverse, join", + "original_id": "EllenWasbo.cutlings.duplicateReverseJoin", + "license": "GNU GPL v2", + "license_url": "https://gitlab.com/EllenWasbo/inkscape-extension-duplicatereversejoin/-/blob/master/duplicateReverseJoin.py", + "comment": "", + "source_url": "https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/duplicate_reverse_joi", + "fork_url": "https://gitlab.com/EllenWasbo/inkscape-extension-duplicatereversejoin", + "documentation_url": "https://stadtfabrikanten.org/pages/viewpage.action?pageId=120525059", + "inkscape_gallery_url": null, + "main_authors": [ + "gitlab.com/EllenWasbo", + "github.com/vmario89" + ] + } +] \ No newline at end of file