Table of Contents

CadRender

from OpenCAD2D import CadRender

class CadRender(System.Object) ยท CadRender in the .NET reference

Draws a drawing of a file to pixels, an SVG or a PDF with no window, as the canvas of the app draws it: the same renderer, the same fonts and the same colours, so that a picture of a drawing is the pixels the app's canvas shows of it (with its grid, UCS icon and grips off, which are the canvas's and not the drawing's). It draws with the app's default settings, never the user's: a picture is the same on every machine that has the same fonts.

Methods

Draw

.NET

@staticmethod
def Draw(document: CadDocument, options: CadRenderOptions) -> CadRenderImage

Draws a space of a drawing and gives its pixels, as the canvas of the app draws it: nothing selected, the drawing's lineweights shown where its $LWDISPLAY says so, and images read before the picture is drawn. A drawing whose extents are 400 by 300 mm is a picture of 1 600 by 1 200 pixels, 5 760 000 bytes.

DrawLabels

.NET

@staticmethod
def DrawLabels(
    document: CadDocument,
    options: CadRenderOptions,
    classes: Sequence[int] | System.Array[int],
) -> CadRenderLabels

Draws a space of a drawing in flat ids and gives, for every pixel, the class of what is drawn on it and the entity that draws it: the picture CadRender.Draw makes for the same options, as labels for training a vision model. It is the renderer of the canvas, drawing each item in the colour that is its id with no antialiasing, in the order the drawing draws them, so what is on top in the picture is on top in the labels; a pixel is of one entity and one class, exactly. A text under 5 pixels high is a bar, as in the picture; the paper of a layout, the frame of a viewport and raster images are not labelled. The classes are those of CadLabelClass. An INSERT's items are classed by what they are unless blocks are asked for, when all of them are class 5. The ground option has no effect: the ground is class 0.

Prepare

.NET

@staticmethod
def Prepare(document: CadDocument) -> None

Sets a drawing up as the app sets one up on opening it, so that a picture of it is the canvas's: the canvas's measure of TrueType letters (once in the process: MTEXT of several looks is laid out with it), the fonts and support folders of the default settings, and their default lineweight. A drawing of CadDocument.Open draws its text in the canvas's font until this is done and lays an MTEXT out with every letter 0.6 of its height wide. A display built before is laid out again, once: preparing a drawing again does nothing. The other members call it first, so it is needed only to read the bounds or the display of a drawing as the picture sees them.

Transform

.NET

@staticmethod
def Transform(document: CadDocument, options: CadRenderOptions) -> System.Array[float]

Gives the matrix from the drawing to the pixels of the picture CadRender.Draw makes for the same options: the very view the renderer draws by, nine numbers of a 3 by 3 row by row, [a, c, e, b, d, f, 0, 0, 1], so that a point (x, y) of the space is at the pixel position (a x + c y + e, b x + d y + f). Pixel (column, row) is the square from (column, row) to (column + 1, row + 1), row 0 at the top and y of the drawing upward, so the pixel a point falls in is the floor of both numbers and the centre of a pixel is at column + 0.5. For a drawing 400 by 300 whose extents are drawn at 1 600 by 1 200 pixels with the margin ZOOM Extents leaves (a scale of 3.6), the point (0, 0) is at (80, 1 140) and (400, 300) at (1 520, 60). On a layout it maps the paper in millimetres; the model entities a viewport shows have the viewport's own matrix on top, which is not given here. The inverse is the matrix inverted.

WritePdf

.NET

@staticmethod
def WritePdf(path: str, document: CadDocument, layout: str) -> CadPlotPage

Plots a space of a drawing to a PDF file of one page, replacing a file of the name, as EXPORTPDF does: the page setup of the layout (its sheet, scale and plot style), the lines at the lineweights of the plot, text as text, and for model space the extents. An A3 sheet on its side is 1 190.5512 by 841.8898 points. A space with no sheet recorded in its plot settings (a drawing made in code, never set up) is fitted to the default sheet, ISO A3, as AutoCAD fits a page setup it has not been given; one with a sheet is plotted at the scale it records.

WritePng

.NET

@staticmethod
def WritePng(path: str, document: CadDocument, options: CadRenderOptions) -> None

Draws a space of a drawing to a PNG file, replacing a file of the name: the picture of CadRender.Draw as 8-bit red, green and blue with no alpha, as PNGOUT writes it.

WriteSvg

.NET

@staticmethod
def WriteSvg(path: str, document: CadDocument, options: CadRenderOptions) -> None

Draws a space of a drawing to an SVG file, replacing a file of the name: the picture of CadRender.WritePng in vectors, its width and height the pixels of the picture, the images in it as PNG data. It is drawn by the renderer of the canvas, so it keeps the canvas's level of detail at the picture's size: an item under half a pixel is one dot, a text under 5 pixels high is a solid bar of its colour and a hatch whose lines come closer than 2 pixels is a tint. The PDF of CadRender.WritePdf is the full-detail form.