diff --git a/extensions/fablabchemnitz/dxfdwgimporter/dxfdwgimporter.py b/extensions/fablabchemnitz/dxfdwgimporter/dxfdwgimporter.py index 41409693..48ad77f9 100644 --- a/extensions/fablabchemnitz/dxfdwgimporter/dxfdwgimporter.py +++ b/extensions/fablabchemnitz/dxfdwgimporter/dxfdwgimporter.py @@ -121,10 +121,11 @@ class DXFDWGImport(inkex.EffectExtension): self.arg_parser.add_argument("--XLINE", type=inkex.Boolean, default=True) def openExplorer(self, temp_output_dir): + DETACHED_PROCESS = 0x00000008 if os.name == 'nt': - subprocess.Popen(["explorer",temp_output_dir], close_fds=True) + subprocess.Popen(["explorer", temp_output_dir], close_fds=True, creationflags=DETACHED_PROCESS).wait() else: - subprocess.Popen(["xdg-open",temp_output_dir], close_fds=True) + subprocess.Popen(["xdg-open", temp_output_dir], close_fds=True, start_new_session=True).wait() def effect(self): #get input file and copy it to some new temporary directory diff --git a/extensions/fablabchemnitz/export_selection.inx b/extensions/fablabchemnitz/export_selection.inx index 78e188bf..546a11dc 100644 --- a/extensions/fablabchemnitz/export_selection.inx +++ b/extensions/fablabchemnitz/export_selection.inx @@ -1,9 +1,14 @@ - <_name>Export selection as SVG - fablabchemnitz.de.export_selection_as_svg + <_name>Export selection as SVG/DXF + fablabchemnitz.de.export_selection_as_svg_dxf false ./inkscape_export/ + false + /usr/share/inkscape/extensions/dxf_outlines.py + false + false + all Export selection to separate SVG file. diff --git a/extensions/fablabchemnitz/export_selection.py b/extensions/fablabchemnitz/export_selection.py index e3692440..9f4b17c7 100644 --- a/extensions/fablabchemnitz/export_selection.py +++ b/extensions/fablabchemnitz/export_selection.py @@ -1,12 +1,17 @@ -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 + from copy import deepcopy from pathlib import Path import logging import math import os +import subprocess +from subprocess import Popen, PIPE import inkex import inkex.command +from inkex.command import inkscape, inkscape_command + from lxml import etree from scour.scour import scourString @@ -21,15 +26,29 @@ class ExportObject(inkex.EffectExtension): def add_arguments(self, pars): pars.add_argument("--wrap_transform", type=inkex.Boolean, default=False, help="Wrap final document in transform") pars.add_argument("--export_dir", default="~/inkscape_export/", help="Location to save exported documents") + pars.add_argument("--opendir", type=inkex.Boolean, default=False, help="Open containing output directory after export") + pars.add_argument("--dxf_exporter_path", default="/usr/share/inkscape/extensions/dxf_outlines.py", help="Location of dxf_outlines.py") + pars.add_argument("--export_dxf", type=inkex.Boolean, default=False, help="Create a dxf file") + pars.add_argument("--newwindow", type=inkex.Boolean, default=False, help="Open file in new Inkscape window") + + + def openExplorer(self, dir): + DETACHED_PROCESS = 0x00000008 + if os.name == 'nt': + Popen(["explorer", dir], close_fds=True, creationflags=DETACHED_PROCESS).wait() + else: + Popen(["xdg-open", dir], close_fds=True, start_new_session=True).wait() def effect(self): if not self.svg.selected: + inkex.errormsg("Selection is empty. Please select some objects first!") return export_dir = Path(self.absolute_href(self.options.export_dir)) os.makedirs(export_dir, exist_ok=True) bbox = inkex.BoundingBox() + for elem in self.svg.selected.values(): transform = inkex.Transform() parent = elem.getparent() @@ -61,8 +80,8 @@ class ExportObject(inkex.EffectExtension): width = math.ceil(bbox.width) height = math.ceil(bbox.height) template.attrib['viewBox'] = f'0 0 {width} {height}' - template.attrib['width'] = f'{width}' - template.attrib['height'] = f'{height}' + template.attrib['width'] = f'{width}' + self.svg.unit + template.attrib['height'] = f'{height}' + self.svg.unit if filename is None: filename = elem.attrib.get('id', None) @@ -74,14 +93,27 @@ class ExportObject(inkex.EffectExtension): template.append(group) if not self.options.wrap_transform: - self.load(inkex.command.inkscape_command(template.tostring(), select=GROUP_ID, verbs=['SelectionUnGroup'])) + self.load(inkscape_command(template.tostring(), select=GROUP_ID, verbs=['SelectionUnGroup'])) template = self.svg for child in template.getchildren(): if child.tag == '{http://www.w3.org/2000/svg}metadata': template.remove(child) self.save_document(template, export_dir / filename) - + + if self.options.opendir is True: + self.openExplorer(export_dir) + + if self.options.newwindow is True: + inkscape(os.path.join(export_dir, filename)) + + if self.options.export_dxf is True: + #ensure that python3 command is available #we pass 25.4/96 which stands for unit mm. See inkex.units.UNITS and dxf_outlines.inx + cmd = ['python3', self.options.dxf_exporter_path, '--output=' + os.path.join(export_dir, filename + '.dxf'), r'--units=25.4/96', os.path.join(export_dir, filename)] + proc = Popen(cmd, shell=False, stdout=PIPE, stderr=PIPE) + stdout, stderr = proc.communicate() + #inkex.utils.debug("%d %s %s" % (proc.returncode, stdout, stderr)) + def create_document(self): document = self.svg.copy() for child in document.getchildren(): diff --git a/extensions/fablabchemnitz/roland_cutstudio.py b/extensions/fablabchemnitz/roland_cutstudio.py index 4489ba8c..6b692031 100644 --- a/extensions/fablabchemnitz/roland_cutstudio.py +++ b/extensions/fablabchemnitz/roland_cutstudio.py @@ -454,7 +454,7 @@ else: #check if we have access to "wine" "Please open that with CutStudio manually. \n\n" + \ "Tip: On Linux, you can use 'wine' to install CutStudio 3.10. Then, the file will be directly opened with CutStudio. \n" + \ " Diagnostic information: \n" + str(exc)) - #os.popen("/usr/bin/xdg-open " + filename) + #os.popen("/usr/bin/xdg-open " + filename) #os.popen is deprecated. Use subprocess.Popen #Popen(["inkscape", filename+".filtered.svg"], stderr=DEVNULL) #Popen(["inkscape", filename+".cutstudio.eps"]) #os.unlink(filename+".filtered.svg")