Several bugfixes in DXF/DWG Importer

This commit is contained in:
Mario Voigt 2020-09-09 02:17:34 +02:00
parent 5a06de7bd9
commit a724a3dc12
1 changed files with 16 additions and 12 deletions

View File

@ -26,7 +26,8 @@ import inkex
import sys import sys
import os import os
import re import re
import subprocess, tempfile import subprocess
import tempfile
from lxml import etree from lxml import etree
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import shutil import shutil
@ -112,9 +113,9 @@ class DXFDWGImport(inkex.Effect):
def openExplorer(self, temp_output_dir): def openExplorer(self, temp_output_dir):
if os.name == 'nt': if os.name == 'nt':
subprocess.Popen(["explorer",temp_output_dir],close_fds=True) subprocess.Popen(["explorer",temp_output_dir], close_fds=True)
else: else:
subprocess.Popen(["xdg-open",temp_output_dir],close_fds=True) subprocess.Popen(["xdg-open",temp_output_dir], close_fds=True)
def effect(self): def effect(self):
#get input file and copy it to some new temporary directory #get input file and copy it to some new temporary directory
@ -357,8 +358,8 @@ class DXFDWGImport(inkex.Effect):
if emptyGroup is not None: if emptyGroup is not None:
emptyGroup.getparent().remove(emptyGroup) emptyGroup.getparent().remove(emptyGroup)
#empty the following vals because they destroy the size aspects of the import #empty the following vals because they destroy the size aspects of the import / make viewbox looking wrong
if self.options.dxf_to_svg_parser == "bjnortier": if self.options.dxf_to_svg_parser == "bjnortier" or self.options.dxf_to_svg_parser == "kabeja":
doc.set('width','') doc.set('width','')
doc.set('height','') doc.set('height','')
doc.set('viewBox','') doc.set('viewBox','')
@ -371,19 +372,22 @@ class DXFDWGImport(inkex.Effect):
#if child.tag == inkex.addNS('g','svg'): #if child.tag == inkex.addNS('g','svg'):
elements.append(child) elements.append(child)
#build some of bounding boxes and ignore errors for faulty elements (sum function often fails for that usecase!) #build sum of bounding boxes and ignore errors for faulty elements (sum function often fails for that usecase!)
bbox = None bbox = None
try: try:
bbox = elements[0].bounding_box() #init with the first bounding box of the tree (and hope that it is not a faulty one) bbox = elements[0].bounding_box() #init with the first bounding box of the tree (and hope that it is not a faulty one)
except: except Exception as e:
#inkex.utils.debug(str(e))
pass pass
count = 0 count = 0
for element in elements: for element in elements:
if count == 0: continue #skip the first if count != 0: #skip the first
try: try:
bbox.add(element.bounding_box()) #bbox.add(element.bounding_box())
except: bbox += element.bounding_box()
pass except Exception as e:
#inkex.utils.debug(str(e))
pass
count += 1 #some stupid counter count += 1 #some stupid counter
if bbox is not None: if bbox is not None:
root = self.svg.getElement('//svg:svg'); root = self.svg.getElement('//svg:svg');