I am reading a dxf file using ezdxf
in python, so that I can display the file and draw some additional lines on it and then export it as a pdf or png. However, the kernel keeps on crashing when I try to display my original file (around 150 MB) using Frontend(ctx, out).draw_layout(doc.modelspace(), finalize=True)
and only works for smaller test files (couple of KB). I also see that the code requires really a lot of memory (more than 50 GB) when running the code on the original file. The error message is pretty generic Canceled future for execute_request message before replies were done
Code sample:
import ezdxf
from ezdxf import colors, recover
from ezdxf.addons.drawing import RenderContext, Frontend
from ezdxf.addons.drawing.matplotlib import MatplotlibBackend
from ezdxf.tools.standards import setup_drawing
from ezdxf.enums import TextEntityAlignment
import matplotlib.pyplot as plt
import sys
dxf_filename = "test.dxf"
try:
doc = ezdxf.readfile(dxf_filename)
print("Successfully read the file")
except IOError:
print(f"Not a DXF file or a generic I/O error.")
sys.exit(1)
except ezdxf.DXFStructureError:
print(f"Invalid or corrupted DXF file.")
sys.exit(2)
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ctx = RenderContext(doc)
out = MatplotlibBackend(ax)
Frontend(ctx, out).draw_layout(doc.modelspace(), finalize=True)
fig.savefig('your.png', dpi=600)
I am not very familiar with reading dxf files, but I can perfectly open and save it as a PNG or PDF in Adobe Illustrator on my computer. So it must be something that ezdxf is doing that overruns my RAM?