From 4429dc95e4b91986836a9350a35c378137c52912 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Fri, 15 Oct 2021 18:30:15 +0200 Subject: added some stuff need to make more stable --- inkscape.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 inkscape.py (limited to 'inkscape.py') diff --git a/inkscape.py b/inkscape.py new file mode 100644 index 0000000..834dcd0 --- /dev/null +++ b/inkscape.py @@ -0,0 +1,35 @@ +import xml.etree.ElementTree as et +import subprocess + + +def distribute(ids, mode): + print(ids) + with open("/home/mike/neuron.d/static/currently_editing", "r") as f: + currently_editing = f.readline() + + print(currently_editing) + + selected = "" + for id in ids: + selected = selected + "select-by-id:" + id + ";" + + subprocess.run([ + 'inkscape', '--actions', + f'{selected}object-distribute:{mode};export-filename:{currently_editing};export-overwrite;export-do;', + currently_editing + ]) + # inkscape --actions="select-by-id:rect878;select-by-id:rect1814;select-by-id:rect1812;object-distribute:hgap;export-filename:/home/mike/neuron.d/static/index/another-one.svg;export-overwrite;export-do;" /home/mike/neuron.d/static/index/another-one.svg + + +def ids_from_xml(xml_string): + ids = [] + root = et.fromstring(xml_string) + for child in root: + # TODO: match for actual tag somehow + if child.tag[-2:] == "}g": + copied_objects = child + break + print(copied_objects.get("id")) + for obj in copied_objects: + ids.append(obj.get("id")) + return ids -- cgit v1.2.3