Exporting complete paperspace into png or pdf #1031
Replies: 3 comments 6 replies
-
The Frontend class of the Tutorial for image export: https://ezdxf.mozman.at/docs/tutorials/image_export.html |
Beta Was this translation helpful? Give feedback.
-
import pathlib
import ezdxf
from ezdxf.addons.drawing import Frontend, RenderContext
from ezdxf.addons.drawing.config import (
Configuration,
BackgroundPolicy,
ColorPolicy,
LineweightPolicy,
)
from ezdxf.addons.drawing import pymupdf, layout
def export(filepath: pathlib.Path, layout_names=("Model",), scale=1):
doc = ezdxf.readfile(filepath)
for layout_name in layout_names:
outname = pathlib.Path(filepath.stem + f"-[{layout_name}]" + ".pdf")
print(outname)
if layout_name == "Model":
dxf_layout = doc.modelspace()
page = layout.Page(
0, # auto-detect
0, # auto-detect
layout.Units.mm, # 1 drawing unit = 1mm
layout.Margins.all(0),
max_width=1189, # limit page width to 1189mm
max_height=841, # limit page height to 841mm
)
settings = layout.Settings(scale=scale)
else:
try:
dxf_layout = doc.paperspace(layout_name)
except KeyError:
print(f"Layout '{layout_name}' not found")
continue
page = layout.Page.from_dxf_layout(dxf_layout)
settings = layout.Settings(
fit_page=False,
scale=dxf_layout.get_plot_unit_scale_factor() * scale,
)
backend = pymupdf.PyMuPdfBackend()
config = Configuration(
background_policy=BackgroundPolicy.WHITE,
color_policy=ColorPolicy.MONOCHROME_LIGHT_BG,
lineweight_policy=LineweightPolicy.RELATIVE,
)
Frontend(RenderContext(doc), backend, config=config).draw_layout(dxf_layout)
pdf_bytes = backend.get_pdf_bytes(page, settings=settings)
outname.write_bytes(pdf_bytes)
if __name__ == "__main__":
export(pathlib.Path(r"A_000217.dxf"), ["Model", "Layout1"]) This script creates the two PDFs:
|
Beta Was this translation helpful? Give feedback.
-
Hi all, Continuing this thread since it is relevant to my query. In the image below, you see a paperspace of a file. There are certain elements frozen in different viewports. I am trying to plot this paperspace as seen. Is there a way to plot the layout, considering the frozen layers? At the moment, plotting this paperspace shows all the elements in all of the viewports regardless of the frozen layers. |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I am trying to export a complete paperspace into a png or pdf. Everything you see in the paperspace when opening the dxf.
So far I found documentation about exporting certain regions of the model space but not for entire paperspaces.
Is there anything available out of the box?
I guess an alternative could be to export all viewports and than stitch them back together?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions