added Vektorkollektor contribution

This commit is contained in:
Mario Voigt 2021-08-04 02:02:12 +02:00
parent d51b765cf4
commit d9efea5afd
2 changed files with 134 additions and 0 deletions

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>Vektorkollektor</name>
<id>fablabchemnitz.de.vektorkollektor</id>
<param name="tab" type="notebook">
<page name="tab_settings" gui-text="Settings">
<param name="vk_url" type="string" gui-text="Data URL" gui-description="default: http://www.vektorkollektor.com/vektordaten/vektorkollektor.js">http://www.vektorkollektor.com/vektordaten/vektorkollektor.js</param>
<param name="vk_id" type="int" gui-text="Vektorkollektor ID" min="0" max="99999" gui-description="The desired Vektorkolletor drawing ID">0</param>
</page>
<page name="tab_about" gui-text="About">
<label appearance="header">Vektorkollektor</label>
<label>This extension generates SVG data from given plt data.</label>
<label>2021 / written by Mario Voigt (Stadtfabrikanten e.V. / FabLab Chemnitz)</label>
<spacer/>
<label appearance="header">Online Documentation</label>
<label appearance="url">https://y.stadtfabrikanten.org/vektorkollektor</label>
<spacer/>
<label appearance="header">Contributing</label>
<label appearance="url">https://gitea.fablabchemnitz.de/FabLab_Chemnitz/mightyscape-1.X</label>
<label appearance="url">mailto:mario.voigt@stadtfabrikanten.org</label>
<spacer/>
<label appearance="header">MightyScape Extension Collection</label>
<label>This piece of software is part of the MightyScape for Inkscape Extension Collection and is licensed under GNU GPL v3</label>
<label appearance="url">https://y.stadtfabrikanten.org/mightyscape-overview</label>
</page>
<page name="tab_donate" gui-text="Donate">
<label appearance="header">Coffee + Pizza</label>
<label>We are the Stadtfabrikanten, running the FabLab Chemnitz since 2016. A FabLab is an open workshop that gives people access to machines and digital tools like 3D printers, laser cutters and CNC milling machines.</label>
<spacer/>
<label>You like our work and want to support us? You can donate to our non-profit organization by different ways:</label>
<label appearance="url">https://y.stadtfabrikanten.org/donate</label>
<spacer/>
<label>Thanks for using our extension and helping us!</label>
<image>../000_about_fablabchemnitz.svg</image>
</page>
</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="FabLab Chemnitz"/>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">vektorkollektor.py</command>
</script>
</inkscape-extension>

View File

@ -0,0 +1,88 @@
#!/usr/bin/env python3
'''
An extension to generate SVG files from plt files (Niklas Roy/Kai Hyyppä from Vektorkollektor)
Made by FabLab Chemnitz / Stadtfabrikanten e.V. - Developer: Mario Voigt (year 2021)
Vektorkollektor Team: Kati Hyyppa [http://katihyyppa.com] & Niklas Roy [https://niklasroy.com]
http://vektorkollektor.com
'''
import os
import urllib.request
from lxml import etree
import inkex
from inkex import PathElement, Path
import re
from ast import literal_eval
class Vektorkollektor(inkex.EffectExtension):
def add_arguments(self, pars):
pars.add_argument("--tab")
pars.add_argument("--vk_url", default="http://www.vektorkollektor.com/vektordaten/vektorkollektor.js")
pars.add_argument("--vk_id", type=int, default=1)
def effect(self):
# Adjust the document view for the desired sticker size
root = self.svg.getElement("//svg:svg")
#clean the document (make it blank) to avoid printing duplicated things
ct = 0
for node in self.document.xpath('//*', namespaces=inkex.NSS):
ct = ct + 1
if ct > 3: #we keep svg:svg, sodipodi:namedview and svg:defs which defines the default canvas without any content inside
#inkex.errormsg(str(node))
try:
root.remove(node)
except Exception as e:
pass
#set the document units
self.document.getroot().find(inkex.addNS("namedview", "sodipodi")).set("inkscape:document-units", "px")
# Download the recent vektorkollektor data file and parse it
handler = urllib.request.HTTPBasicAuthHandler()
opener = urllib.request.build_opener(handler)
try:
xP = [] #x-coordinate
yP = [] #y-coordinate
cP = [] #draw
fN = [] #original vektorkollektor .PLT file number
vkData = opener.open(self.options.vk_url).read().decode("utf-8")
urllib.request.install_opener(opener)
for match in re.compile(r"""^var xP = .*;""", re.MULTILINE).finditer(vkData):
xP = literal_eval(match.group(0).split("var xP = ")[1].split(";")[0])
for match in re.compile(r"""^var yP = .*;""", re.MULTILINE).finditer(vkData):
yP = literal_eval(match.group(0).split("var yP = ")[1].split(";")[0])
for match in re.compile(r"""^var cP = .*;""", re.MULTILINE).finditer(vkData):
cP = literal_eval(match.group(0).split("var cP = ")[1].split(";")[0])
for match in re.compile(r"""^var fN = .*;""", re.MULTILINE).finditer(vkData):
fN = literal_eval(match.group(0).split("var fN = ")[1].split(";")[0])
vkGroup = self.document.getroot().add(inkex.Group(id="vektorkollektor-{}".format(self.options.vk_id)))
for move in range(0, len(fN)):
begin = None
end = None
if fN[move] == self.options.vk_id:
if cP[move] == 0: #pen up (reset)
begin = None
end = None
#self.msg("xP={}, yP={}, pen up".format(xP[move], yP[move]))
if cP[move] == 1:#pen down
begin = [xP[move-1], yP[move-1]]
end = [xP[move], yP[move]]
#self.msg("xP={}, yP={}, pen down".format(xP[move], yP[move]))
if begin is not None and end is not None:
newLine = PathElement(id="vkLine-{}".format(move))
newLine.path = Path("M {},{} L {},{}".format(begin[0], begin[1], end[0], end[1]))
newLine.style = "fill:none;stroke:#000000;stroke-width:1;stroke-linecap:round"
vkGroup.append(newLine)
except Exception as e:
inkex.errormsg(e)
if __name__ == "__main__":
Vektorkollektor().run()