Dividing dxf into grids and plot them on png? #451
-
Hi, thanks for this great library! I want to divide a dxf into grids and save those grids one-by-one to a png file. To do this, I created different layouts for each grid. I want to print those layouts to png using the following code segment but instead it plots the whole dxf. I checked the layouts using AutoDesk Viewer and they seem fine. However, I couldn't get to print layouts on png. Is there a better way to save grids on different png files? If not so how can I plot different layouts to png files? Can you please help? layout2 = doc.layout('Layout2')
param = {"show_hatch": 0, "hatch_pattern": 0}
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ctx = RenderContext(doc, export_mode=False)
ctx.set_current_layout(layout2)
ctx.current_layout.set_colors(bg="#FFFFFFFF")
out = MatplotlibBackend(ax, params=param)
Frontend(ctx, out).draw_layout(layout2, finalize=True)
fig.savefig("Layout2.png", dpi=600) The drawing is as this: And I wanted to save grids to png file like this (like zoomed version of patches): Instead I get this: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
can you explain how you are constructing these additional zoomed in layouts? they seem to not be using viewports or you would not see the shapes in the image you posted (the drawing addon does not support viewports yet). fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
...
Frontend(ctx, out).draw_layout(layout2, finalize=True)
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax) you have to be careful to maintain the aspect ratio though. you can adjust the figure size to maintain the correct aspect ratio. |
Beta Was this translation helpful? Give feedback.
can you explain how you are constructing these additional zoomed in layouts? they seem to not be using viewports or you would not see the shapes in the image you posted (the drawing addon does not support viewports yet).
Are you setting the view boundary for the layout or something? the drawing addon completely ignores these because they are usually useless.
If you are able to calculate / find the view limits and you just want to set them on the axes after drawing then you can do:
you have to be careful to maintain the aspect ratio t…