small enhancement in invetory sticker, added quick svg reload extension
This commit is contained in:
parent
7d567fd928
commit
375ccb664d
@ -397,15 +397,9 @@ class InventorySticker(inkex.Effect):
|
||||
root.set("viewBox", "%f %f %f %f" % (0, 0, sticker_width, sticker_height))
|
||||
|
||||
#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
|
||||
if node.TAG not in ('svg', 'defs', 'namedview'):
|
||||
node.delete()
|
||||
|
||||
#set the document units
|
||||
self.document.getroot().find(inkex.addNS("namedview", "sodipodi")).set("inkscape:document-units", "px")
|
||||
|
14
extensions/fablabchemnitz/reload/reload.inx
Normal file
14
extensions/fablabchemnitz/reload/reload.inx
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
|
||||
<name>Reload drawing</name>
|
||||
<id>fablabchemnitz.de.reload</id>
|
||||
<effect needs-document="true" needs-live-preview="false">
|
||||
<object-type>all</object-type>
|
||||
<effects-menu>
|
||||
<submenu name="FabLab Chemnitz"/>
|
||||
</effects-menu>
|
||||
</effect>
|
||||
<script>
|
||||
<command location="inx" interpreter="python">reload.py</command>
|
||||
</script>
|
||||
</inkscape-extension>
|
32
extensions/fablabchemnitz/reload/reload.py
Normal file
32
extensions/fablabchemnitz/reload/reload.py
Normal file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import inkex
|
||||
from lxml import etree
|
||||
|
||||
class Reload(inkex.EffectExtension):
|
||||
|
||||
def effect(self):
|
||||
currentDoc = self.document_path()
|
||||
if currentDoc == "":
|
||||
self.msg("Your document is not saved as a permanent file yet. Cannot reload.")
|
||||
exit(1)
|
||||
stream = open(self.document_path(), 'r')
|
||||
p = etree.XMLParser(huge_tree=True)
|
||||
doc = etree.parse(stream, parser=etree.XMLParser(huge_tree=True))
|
||||
stream.close()
|
||||
root = self.document.getroot()
|
||||
kept = [] #required. if we delete them directly without adding new defs or namedview, inkscape will crash
|
||||
for node in self.document.xpath('//*', namespaces=inkex.NSS):
|
||||
if node.TAG not in ('svg', 'defs', 'namedview'):
|
||||
node.delete()
|
||||
elif node.TAG in ('defs', 'namedview'): #except 'svg'
|
||||
kept.append(node)
|
||||
|
||||
children = doc.getroot().getchildren()
|
||||
for child in children:
|
||||
root.append(child)
|
||||
for k in kept:
|
||||
k.delete()
|
||||
|
||||
if __name__ == '__main__':
|
||||
Reload().run()
|
Reference in New Issue
Block a user