From e6db17cdd3427384a38dbd8595ea6c63d68d7267 Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Thu, 6 May 2021 16:00:57 +0200 Subject: [PATCH] fixes in dxf2papercraft --- .../fablabchemnitz/dxf2papercraft/debug.dat | 0 .../dxf2papercraft/delete_me_later | 4 ++++ .../dxf2papercraft/dxf2papercraft.inx | 2 +- .../dxf2papercraft/dxf2papercraft.py | 23 +++++++++---------- 4 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 extensions/fablabchemnitz/dxf2papercraft/debug.dat create mode 100644 extensions/fablabchemnitz/dxf2papercraft/delete_me_later diff --git a/extensions/fablabchemnitz/dxf2papercraft/debug.dat b/extensions/fablabchemnitz/dxf2papercraft/debug.dat new file mode 100644 index 00000000..e69de29b diff --git a/extensions/fablabchemnitz/dxf2papercraft/delete_me_later b/extensions/fablabchemnitz/dxf2papercraft/delete_me_later new file mode 100644 index 00000000..d425fa93 --- /dev/null +++ b/extensions/fablabchemnitz/dxf2papercraft/delete_me_later @@ -0,0 +1,4 @@ +#VRML V1.0 ascii + +Separator { +} diff --git a/extensions/fablabchemnitz/dxf2papercraft/dxf2papercraft.inx b/extensions/fablabchemnitz/dxf2papercraft/dxf2papercraft.inx index 4250fef1..8391e268 100644 --- a/extensions/fablabchemnitz/dxf2papercraft/dxf2papercraft.inx +++ b/extensions/fablabchemnitz/dxf2papercraft/dxf2papercraft.inx @@ -9,7 +9,7 @@ false false false - false + false false diff --git a/extensions/fablabchemnitz/dxf2papercraft/dxf2papercraft.py b/extensions/fablabchemnitz/dxf2papercraft/dxf2papercraft.py index 10564d37..d2447059 100644 --- a/extensions/fablabchemnitz/dxf2papercraft/dxf2papercraft.py +++ b/extensions/fablabchemnitz/dxf2papercraft/dxf2papercraft.py @@ -121,29 +121,28 @@ class PapercraftUnfold(inkex.EffectExtension): p = etree.XMLParser(huge_tree=True) doc = etree.parse(stream, parser=etree.XMLParser(huge_tree=True)).getroot() stream.close() - doc.set('id', self.svg.get_unique_id('dxf2papercraft-')) - self.document.getroot().append(doc) - - #do some viewport adjustments - doc.set('width','') - doc.set('height','') - doc.set('viewBox','') - doc.getchildren()[1].set('transform','') #this removes the "transform:scale(1, -1)" from child within dxf2papercraft- group - + + dxfGroup = inkex.Group(id=self.svg.get_unique_id("dxf2papercraft-")) + for element in doc.iter("{http://www.w3.org/2000/svg}g"): + if element.get('id') != "draft": + dxfGroup.append(element) + self.document.getroot().add(dxfGroup) + #apply scale factor - node = doc.getchildren()[1] translation_matrix = [[self.options.scalefactor, 0.0, 0.0], [0.0, self.options.scalefactor, 0.0]] - node.transform = Transform(translation_matrix) * node.transform + dxfGroup.transform = Transform(translation_matrix) * dxfGroup.transform #Adjust viewport and width/height to have the import at the center of the canvas if self.options.resizetoimport: - bbox = inkex.elements._selected.ElementList.bounding_box(node) + bbox = dxfGroup.bounding_box() #does not work. why? if bbox is not None: root = self.svg.getElement('//svg:svg'); offset = self.svg.unittouu(str(self.options.extraborder) + self.options.extraborder_units) root.set('viewBox', '%f %f %f %f' % (bbox.left - offset, bbox.top - offset, bbox.width + 2 * offset, bbox.height + 2 * offset)) root.set('width', bbox.width + 2 * offset) root.set('height', bbox.height + 2 * offset) + else: + self.msg("Error resizing to bounding box.") if __name__ == '__main__': PapercraftUnfold().run() \ No newline at end of file