some small additions to code quality

This commit is contained in:
Mario Voigt 2021-03-04 22:09:08 +01:00
parent 9121ab388d
commit 8d9e0ddf5b

View File

@ -312,28 +312,39 @@ class DXFDWGImport(inkex.Effect):
if self.options.opendironerror: if self.options.opendironerror:
self.openExplorer(temp_output_dir) self.openExplorer(temp_output_dir)
elif self.options.dxf_to_svg_parser == "ezdxf": elif self.options.dxf_to_svg_parser == "ezdxf":
doc = ezdxf.readfile(dxf_file) try:
#doc.header['$DIMSCALE'] = 0.2 does not apply to the plot :-( doc = ezdxf.readfile(dxf_file)
#inkex.utils.debug(doc.header['$DIMSCALE']) #msp = doc.modelspace() #loop through entities
#inkex.utils.debug(doc.header['$MEASUREMENT']) #for e in msp:
auditor = doc.audit() #audit & repair DXF document before rendering # inkex.errormsg(e)
# The auditor.errors attribute stores severe errors, which *may* raise exceptions when rendering. #doc.header['$DIMSCALE'] = 0.2 does not apply to the plot :-(
if len(auditor.errors) == 0: #inkex.utils.debug(doc.header['$DIMSCALE'])
fig = plt.figure() #inkex.utils.debug(doc.header['$MEASUREMENT'])
ax = plt.axes([0., 0., 1., 1.], xticks=[], yticks=[]) auditor = doc.audit() #audit & repair DXF document before rendering
#ax = plt.axes([0., 0., 1., 1.], frameon=False, xticks=[], yticks=[]) # The auditor.errors attribute stores severe errors, which *may* raise exceptions when rendering.
ax.patches = [] if len(auditor.errors) == 0:
#plt.axis('off') fig = plt.figure()
plt.margins(0, 0) ax = plt.axes([0., 0., 1., 1.], xticks=[], yticks=[])
plt.gca().xaxis.set_major_locator(plt.NullLocator()) #ax = plt.axes([0., 0., 1., 1.], frameon=False, xticks=[], yticks=[])
plt.gca().yaxis.set_major_locator(plt.NullLocator()) ax.patches = []
plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0) #plt.axis('off')
out = MatplotlibBackend(fig.add_axes(ax)) plt.margins(0, 0)
Frontend(RenderContext(doc), out).draw_layout(doc.modelspace(), finalize=True) plt.gca().xaxis.set_major_locator(plt.NullLocator())
#plt.show() plt.gca().yaxis.set_major_locator(plt.NullLocator())
#fig.savefig(os.path.join(temp_output_dir, outputfilebase + ".png"), dpi=300) plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
fig.savefig(svg_file) #see https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html out = MatplotlibBackend(fig.add_axes(ax))
Frontend(RenderContext(doc), out).draw_layout(msp, finalize=True)
#plt.show()
#fig.savefig(os.path.join(temp_output_dir, outputfilebase + ".png"), dpi=300)
fig.savefig(svg_file) #see https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html
except IOError:
inkex.errormsg("Not a DXF file or a generic I/O error.")
exit(1)
except ezdxf.DXFStructureError:
inkex.errormsg("Invalid or corrupted DXF file.")
exit(1)
elif self.options.dxf_to_svg_parser == "legacy": elif self.options.dxf_to_svg_parser == "legacy":
inkex.utils.debug("The selected legacy DXF to SVG parser is not supported by this extension yet. Use File > Import > *.dxf. This calls the \"dxf_input.inx\" extension.") inkex.utils.debug("The selected legacy DXF to SVG parser is not supported by this extension yet. Use File > Import > *.dxf. This calls the \"dxf_input.inx\" extension.")
exit(1) exit(1)