How do I get a more accurate linetype rendering for the drawing add-on #562
-
I am trying to convert a DXF file to a black&white png file. During the conversion some lines(dotted/dashed) are drawn differently. Every line type have its special meaning so it should be drawn exactly same. I have also attached the actual files for the reference. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The default rendering mode for line types in the from pathlib import Path
import matplotlib.figure as figure
import ezdxf
from ezdxf.addons.drawing import RenderContext, Frontend
from ezdxf.addons.drawing.matplotlib import MatplotlibBackend
from ezdxf.addons.drawing.config import Configuration, LinePolicy
# set your working directory:
DIR = Path("~/Desktop/Now/ezdxf/561").expanduser()
def convert_dxf2img(name: Path):
doc = ezdxf.readfile(name)
msp = doc.modelspace()
# new configuration system for the drawing add-on in ezdxf v0.17:
config = Configuration.defaults()
config = config.with_changes(line_policy=LinePolicy.ACCURATE)
fig = figure.Figure()
ax = fig.add_axes([0, 0, 1, 1])
ctx = RenderContext(doc)
ctx.set_current_layout(msp)
ctx.current_layout_properties.set_colors(bg="#ffffff", fg="#000000")
out = MatplotlibBackend(ax)
frontend = Frontend(ctx, out, config=config)
frontend.draw_layout(msp, finalize=True)
fig.savefig(name.with_suffix(".png"), dpi=300)
if __name__ == "__main__":
convert_dxf2img(DIR / "MBV1G-PB0000047471-2012-06-01-DE-3.dxf") |
Beta Was this translation helpful? Give feedback.
The default rendering mode for line types in the
drawing
add-on isAPPROIXIMATE
, which uses the line type rendering provided by the backend.Matplotlib
andPyQt
render line types in such a way that the same line pattern is always displayed regardless of the view scaling or zoom level. TheACCURATE
line policy is implemented for both backends, which shows a more precise rendering. The modified code uses the new configuration system for thedrawing
add-on and requiresezdxf
v0.17 run: