DXFEngine

DXFEngine is the dxf entity creation factory, the dxfwrite interface.

class DXFEngine

Factory, creates the dxf objects.

This is the dedicated interface to dxfwrite, all table entries and all all DXF entities should be created by the methods of this object. All methods are static methods, so this object hasn’t to be instantiated.

Drawing

DXFEngine.drawing(name='empty.dxf')

Create a new drawing.

The drawing-object contains all the sections, tables and entities, which are necessary for a valid dxf-drawing.

For drawing methods see Drawing class.

Table Entries

DXFEngine.layer(name, **kwargs)

Create a new layer.

Parameters:
  • name (str) – layer name
  • flags (int) – standard flag values, bit-coded, default=0
  • color (int) – color number, negative if layer is off, default=1
  • linetype (str) – linetype name, default=”CONTINUOUS”

See also

LAYER

DXFEngine.style(name, **kwargs)

Create a new textstyle.

Parameters:
  • name (str) – textstyle name
  • flags (int) – standard flag values, bit-coded, default=0
  • generation_flags (int) – text generation flags, default = 0
  • height (float) – fixed text height, 0 if not fixed = default
  • last_height – last height used, default=1.
  • width (float) – width factor, default=1.
  • oblique (float) – oblique angle in degree, default=0.
  • font (str) – primary font filename, default=”ARIAL”
  • bigfont (str) – big-font file name, default=”“

See also

TEXTSTYLE

DXFEngine.linetype(name, **kwargs)

Create a new linetype.

Parameters:
  • name (str) – linetype name
  • flags (int) – standard flag values, bit-coded, default=0
  • description (str) – descriptive text for linetype, default=”“
  • pattern – line pattern definition, see method DXFEngine.linepattern

See also

LINETYPE

DXFEngine.linepattern(pattern)

Create a LINEPATTERN object from pattern-list.

example linepattern([2.0, 1.25, -0.25, 0.25, -0.25]), for format description see object LINEPATTERN.

DXFEngine.view(name, **kwargs)

Create a new view.

Parameters:
  • name (str) – view name
  • flags (int) – standard flag values, bit-coded, default=0 STD_FLAGS_PAPER_SPACE, if set this is a paper space view.
  • height, width (float) – view height and width, in DCS?!, default=1.0
  • center_point – view center point, in DCS?! (xy-tuple), default=(.5, .5)
  • direction_point – view direction from target point, in WCS!! (xyz-tuple), default=(0, 0, 1)
  • target_point – target point, in WCS!! (xyz-tuple), default=(0, 0, 0)
  • lens_length (float) – lens length, default=50
  • front_clipping (float) – front and back clipping planes, offsets from target point, default=0
  • back_clipping – see front_clipping
  • view_twist (float) – twist angle in degree, default=0
  • view_mode (int) – view mode, bit-coded, default=0
DXFEngine.vport(name, **kwargs)

Create a new viewport table entry.

Parameters:
  • name (str) – viewport name
  • flags (int) – standard flag values, bit-coded, default=0
  • lower_left – lower-left corner of viewport, (xy-tuple), default=(0, 0)
  • upper_right – upper-right corner of viewport, (xy-tuple), default=(1, 1)
  • center_point – view center point, in WCS, (xy-tuple), default=(.5, .5)
  • snap_base – snap base point, (xy-tuple), default=(0, 0)
  • snap_spacing – snap spacing, X and Y (xy-tuple), default=(.1, .1)
  • grid_spacing – grid spacing, X and Y (xy-tuple), default=(.1, .1)
  • direction_point – view from direction point to target point (xyz-tuple), default=(0, 0, 1)
  • target_point – view target point (xyz-tuple), default=(0, 0, 0)
  • aspect_ratio – viewport aspect ratio (float), default=1.
  • lens_length (float) – lens length, default=50
  • front_clipping (float) – front and back clipping planes, offsets from target point , default=0
  • back_clipping (float) – see front_clipping
  • view_twist (float) – twist angle in degree, default=0
  • circle_zoom (float) – circle zoom percent, default=100
  • view_mode (int) – view mode, bit-coded, default=0
  • fast_zoom (int) – fast zoom setting, default=1
  • ucs_icon (int) – UCSICON settings, default=3
  • snap_on (int) – snap on/off, default=0
  • grid_on (int) – grid on/off, default=0
  • snap_style (int) – snap style, default=0
  • snap_isopair (int) – snap isopair, default=0

viewmode flags for view and viewport:

  • VMODE_TURNED_OFF
  • VMODE_PERSPECTIVE_VIEW_ACTIVE
  • VMODE_FRONT_CLIPPING_ON
  • VMODE_BACK_CLIPPING_ON
  • VMODE_UCS_FOLLOW_MODE_ON
  • VMODE_FRONT_CLIP_NOT_AT_EYE
DXFEngine.ucs(name, **kwargs)

Create a new user-coordinate-system (UCS).

Parameters:
  • name (str) – ucs name
  • flags (int) – standard flag values, bit-coded
  • origin – origin in WCS (xyz-tuple), default=(0, 0, 0)
  • xaxis – xaxis direction in WCS (xyz-tuple), default=(1, 0, 0)
  • yaxis – yaxis direction in WCS (xyz-tuple), default=(0, 1, 0)
DXFEngine.appid(name)

DXF R12 Entities

DXFEngine.arc(radius=1.0, center=(0., 0.), startangle=0., endangle=360., **kwargs)

Create a new arc-entity.

Parameters:
  • radius (float) – arc radius
  • center – center point (xy- or xyz-tuple), z-axis is 0 by default
  • startangle (float) – start angle in degree
  • endangle (float) – end angle in degree

See also

ARC

DXFEngine.attdef(tag, insert=(0., 0.), **kwargs)

Create a new attribute definition, used in block-definitions.

Parameters:
  • text (str) – attribute default text
  • insert – insert point (xy- or xyz-tuple), z-axis is 0 by default
  • prompt (str) – prompt text, like “insert a value:”
  • tag (str) – attribute tag string
  • flags (int) – attribute flags, bit-coded, default=0
  • length (int) – field length ??? see dxf-documentation
  • height (float) – textheight in drawing units (default=1)
  • rotation (float) – text rotation (default=0) (all DXF angles in degrees)
  • oblique (float) – text oblique angle in degree, default=0
  • xscale (float) – width factor (default=1)
  • style (str) – textstyle (default=STANDARD)
  • mirror (int) – bit coded flags
  • halign (int) – horizontal justification type, LEFT, CENTER, RIGHT, ALIGN, FIT, BASELINE_MIDDLE (default LEFT)
  • valign (int) – vertical justification type, TOP, MIDDLE, BOTTOM, BASELINE (default BASELINE)
  • alignpoint – align point (xy- or xyz-tuple), z-axis is 0 by default, if the justification is anything other than BASELINE/LEFT, alignpoint specify the alignment point (or the second alignment point for ALIGN or FIT).

See also

ATTDEF

DXFEngine.attrib(text, insert=(0., 0.), **kwargs)

Create a new attribute, used in the entities section.

Parameters:
  • text (str) – attribute text
  • insert – insert point (xy- or xyz-tuple), z-axis is 0 by default
  • tag (str) – attribute tag string
  • flags (int) – attribute flags, bit-coded, default=0
  • length (int) – field length ??? see dxf-documentation
  • height (float) – textheight in drawing units (default=1)
  • rotation (float) – text rotation (default=0) (all DXF angles in degrees)
  • oblique (float) – text oblique angle in degree, default=0
  • xscale (float) – width factor (default=1)
  • style (str) – textstyle (default=STANDARD)
  • mirror (int) – bit coded flags
  • halign (int) – horizontal justification type, LEFT, CENTER, RIGHT, ALIGN, FIT, BASELINE_MIDDLE (default LEFT)
  • valign (int) – vertical justification type, TOP, MIDDLE, BOTTOM, BASELINE (default BASELINE)
  • alignpoint – align point (xy- or xyz-tuple), z-axis is 0 by default, if the justification is anything other than BASELINE/LEFT, alignpoint specify the alignment point (or the second alignment point for ALIGN or FIT).

See also

ATTRIB

DXFEngine.block(name, basepoint=(0., 0.), **kwargs)

Create a block definition, for the blocks section.

Parameters:
  • name (str) – blockname
  • basepoint – block base point (xy- or xyz-tuple), z-axis is 0. by default
  • flags (int) – block type flags
  • xref (str) – xref pathname

See also

BLOCK

DXFEngine.circle(radius=1.0, center=(0., 0.), **kwargs)

Create a new circle-entity.

Parameters:
  • radius (float) – circle radius
  • center – center point (xy- or xyz-tuple), z-axis is 0 by default

See also

CIRCLE

DXFEngine.face3d(points=[], **kwargs)

Create a 3Dface entity with 3 or 4 sides of (3D) points, z-axis is 0 by default.

Parameters:
  • points – list of three or four 2D- or 3D-points
  • flags (int) – edge flags, bit-coded, default=0

See also

FACE3D (3DFACE)

DXFEngine.insert(blockname, insert=(0., 0.), **kwargs)

Insert a new block-reference.

Hint: mirroring is scaling by -1, for mirroring about y-axis (x, y => -x, y) use xscale=-1, for mirroring about x-axis (x, y => x, -y) use yscale=-1.

Parameters:
  • blockname (str) – name of block definition
  • insert – insert point (xy- or xyz-tuple), z-axis is 0 by default
  • xscale (float) – x-scale factor, default=1.
  • yscale (float) – y-scale factor, default=1.
  • zscale (float) – z-scale factor, default=1.
  • rotation (float) – rotation angle in degree, default=0.
  • columns (int) – column count, default=1
  • rows (int) – row count, default=1
  • colspacing (float) – column spacing, default=0.
  • rowspacing (float) – row spacing, default=0.
DXFEngine.line(start=(0., 0.), end=(0., 0.), **kwargs)

Create a new line-entity of two (3D) points, z-axis is 0 by default.

Parameters:
  • start – start point (xy- or xyz-tuple)
  • end – end point (xy- or xyz-tuple)

See also

LINE

DXFEngine.point(point=(0., 0.), **kwargs)

Create a new point-entity of one (3D) point, z-axis is 0 by default.

Parameters:
  • point – start point (xy- or xyz-tuple)
  • orientation – a 3D vector (xyz-tuple), orientation of PDMODE images … see dxf documentation

See also

POINT

DXFEngine.polyline(points=[], **kwargs)

Create a new polyline entity. Polymesh and polyface are also polylines.

Parameters:
  • points – list of points, 2D or 3D points, z-value of 2D points is 0.
  • polyline_elevation – polyline elevation (xyz-tuple), z-axis supplies elevation, x- and y-axis has to be 0.)
  • flags (int) – polyline flags, bit-coded, default=0
  • startwidth (float) – default starting width, default=0
  • endwidth (float) – default ending width, default=0
  • mcount (int) – polygon mesh M vertex count, default=0
  • ncount (int) – polygon mesh N vertex count, default=0
  • msmooth_density (int) – (if flags-bit POLYLINE_3D_POLYMESH is set) smooth surface M density, default=0
  • nsmooth_density (int) – (if flags-bit POLYLINE_3D_POLYMESH is set) smooth surface N density, default=0 same values as msmooth_density
  • smooth_surface (int) – curves and smooth surface type, default=0 ??? see dxf-documentation

See also

POLYLINE

DXFEngine.polymesh(nrows, ncols, **kwargs)

Create a new polymesh entity.

nrows and ncols >=2 and <= 256, greater meshes have to be divided into smaller meshes.

The flags-bit POLYLINE_3D_POLYMESH is set.

Parameters:
  • nrows (int) – count of vertices in m-direction, nrows >=2 and <= 256
  • ncols (int) – count of vertices in n-direction, ncols >=2 and <= 256

See also

POLYMESH

DXFEngine.polyface(precision=6, **kwargs)

Create a new polyface entity, polyface is a dxf-polyline entity!

Parameters:precision – vertex-coords will be rounded to precision places, and if the vertex is equal to an other vertex, only one vertex will be used, this reduces filespace, the coords will be rounded only for the comparison of the vertices, the output file has the full float resolution.

See also

POLYFACE

DXFEngine.shape(name, insert=(0., 0.), **kwargs)

Insert a shape-reference.

Parameters:
  • name (str) – name of shape
  • insert – insert point (xy- or xyz-tuple), z-axis is 0 by default
  • xscale (float) – x-scale factor, default=1.
  • rotation (float) – rotation angle in degree, default=0
  • oblique (float) – text oblique angle in degree, default=0

See also

SHAPE

DXFEngine.solid(points=[], **kwargs)

Create a solid-entity by 3 or 4 vertices, the z-axis for 2D-points is 0.

Parameters:points (list) – three or four 2D- or 3D-points (tuples)

See also

SOLID

DXFEngine.trace(points=[], **kwargs)

Create a trace-entity by 3 or 4 vertices, the z-axis for 2D-points is 0.

Parameters:points – list of three or four 2D- or 3D-points (tuples)

See also

TRACE

DXFEngine.text(text, insert=(0., 0.), height=1.0, **kwargs)

Create a new text entity.

Parameters:
  • text (str) – the text to display
  • insert – insert point (xy- or xyz-tuple), z-axis is 0 by default
  • height (float) – text height in drawing-units
  • rotation (float) – text rotation in degree, default=0
  • xscale (float) – text width factor, default=1
  • oblique (float) – text oblique angle in degree, default=0
  • style (str) – text style name, default=STANDARD
  • mirror (int) – text generation flags, bit-coded, default=0
  • halign (int) – horizontal justification type
  • valign (int) – vertical justification type
  • alignpoint – align point (xy- or xyz-tuple), z-axis is 0 by default If the justification is anything other than BASELINE/LEFT, alignpoint specify the alignment point (or the second alignment point for ALIGN or FIT).

any combination of valign (TOP, MIDDLE, BOTTOM) and halign (LEFT, CENTER, RIGHT) is valid.

See also

TEXT

DXFEngine.viewport(center_point, width, height, **kwargs)

Create a new viewport entity.

Parameters:
  • center_point – center point of viewport in paper space as (x, y, z) tuple
  • width (float) – width of viewport in paper space
  • height (float) – height of viewport in paper space
  • status (int) – 0 for viewport is off, >0 ‘stacking’ order, 1 is highest priority
  • view_target_point – as (x, y, z) tuple, default value is (0, 0, 0)
  • view_direction_vector – as (x, y, z) tuple, default value is (0, 0, 0)
  • view_twist_angle (float) – in degrees, default value is 0
  • view_height (float) – default value is 1
  • view_center_point – as (x, y) tuple, default value is (0, 0)
  • perspective_lens_length (float) – default value is 50
  • front_clip_plane_z_value (float) – default value is 0
  • back_clip_plane_z_value (float) – default value is 0
  • view_mode (int) – default value is 0
  • circle_zoom (int) – default value is 100
  • fast_zoom (int) – default value is 1
  • ucs_icon (int) – default value is 3
  • snap (int) – default value is 0
  • grid (int) – default value is 0
  • snap_style (int) – default value is 0
  • snap_isopair (int) – default value is 0
  • snap_angle (float) – in degrees, default value is 0
  • snap_base_point – as (x, y) tuple, default value is (0, 0)
  • snap_spacing – as (x, y) tuple, default value is (0.1, 0.1)
  • grid_spacing – as (x, y) tuple, default value is (0.1, 0.1)
  • hidden_plot (int) – default value is 0

Composite Entities

DXFEngine.mtext(text, insert, linespacing=1.5, **kwargs)

Create a multi-line text buildup MText with simple TEXT entities.

Mostly the same kwargs like TEXT.

Caution

alignpoint is always the insert point, I don’t need a second alignpoint because horizontal alignment FIT, ALIGN, BASELINE_MIDDLE is not supported.

Parameters:
  • text (str) – the text to display
  • insert – insert point (xy- or xyz-tuple), z-axis is 0 by default
  • linespacing (float) – linespacing in percent of height, 1.5 = 150% = 1+1/2 lines
  • height (float) – text height in drawing-units
  • rotation (float) – text rotion in dregree, default=0
  • xscale (float) – text width factor, default=1
  • oblique (float) – text oblique angle in degree, default=0
  • style (str) – text style name, default=STANDARD
  • mirror (int) – text generation flags, bit-coded, default=0
  • halign (int) – horizontal justification type
  • valign (int) – vertical justification type
  • layer (str) – layer name
  • color (int) – range [1..255], 0 = BYBLOCK, 256 = BYLAYER

any combination of valign (TOP, MIDDLE, BOTTOM) and halign (LEFT, CENTER, RIGHT) is valid.

See also

MText

DXFEngine.insert2(blockdef, insert=(0., 0.), attribs={}, **kwargs)

Insert a new block-reference with auto-creating of ATTRIB from ATTDEF, and setting attrib-text by the attribs-dict. (multi-insert is not supported)

Parameters:
  • blockdef – the block definition itself
  • insert – insert point (xy- or xyz-tuple), z-axis is 0 by default
  • xscale (float) – x-scale factor, default=1.
  • yscale (float) – y-scale factor, default=1.
  • zscale (float) – z-scale factor, default=1.
  • rotation (float) – rotation angle in degree, default=0.
  • attribs (dict) – dict with tag:value pairs, to fill the the attdefs in the block-definition. example: {‘TAG1’: ‘TextOfTAG1’}, create and insert an attrib from an attdef (with tag-value == ‘TAG1’), and set text-value of the attrib to value ‘TextOfTAG1’.
  • linetype (str) – linetype name, if not defined = BYLAYER
  • layer (str) – layer name
  • color (int) – range [1..255], 0 = BYBLOCK, 256 = BYLAYER

See also

Insert2

DXFEngine.table(insert, nrows, ncols, default_grid=True)

Table object like a HTML-Table, buildup with basic DXF R12 entities.

Cells can contain Multiline-Text or DXF-BLOCKs, or you can create your own cell-type by extending the CustomCell object.

Cells can span over columns and rows.

Text cells can contain text with an arbitrary rotation angle, or letters can be stacked top-to-bottom.

BlockCells contains block references (INSERT-entity) created from a block definition (BLOCK), if the block definition contains attribute definitions (ATTDEF-entity), attribs created by Attdef.new_attrib() will be added to the block reference (ATTRIB-entity).

Parameters:
  • insert – insert point as 2D or 3D point
  • nrows (int) – row count
  • ncols (int) – column count
  • default_grid (bool) – if True always a solid line grid will be drawn, if False, only explicit defined borders will be drawn, default grid has a priority of 50.

See also

Table

DXFEngine.rectangle(insert, width, height, **kwargs)

2D Rectangle, build with a polyline and a solid as background filling

Parameters:
  • insert (point) – where to place the rectangle
  • width (float) – width in drawing units
  • height (float) – height in drawing units
  • rotation (float) – in degree (circle = 360 degree)
  • halign (int) – LEFT, CENTER, RIGHT
  • valign (int) – TOP, MIDDLE, BOTTOM
  • color (int) – dxf color index, default is BYLAYER, if color is None, no polyline will be created, and the rectangle consist only of the background filling (if bgcolor != None)
  • bgcolor (int) – dxf color index, default is None (no background filling)
  • layer (str) – target layer, default is '0'
  • linetype (str) – linetype name, None = BYLAYER

See also

Rectangle

DXFEngine.ellipse(center, rx, ry, startangle=0., endangle=360., rotation=0., segments=100, **kwargs)

Create a new ellipse-entity, curve shape is an approximation by POLYLINE.

Parameters:
  • center – center point (xy- or xyz-tuple), z-axis is 0 by default
  • rx (float) – radius in x-axis
  • ry (float) – radius in y-axis
  • startangle (float) – in degree
  • endangle (float) – in degree
  • rotation (float) – angle between x-axis and ellipse-main-axis in degree
  • segments (int) – count of line segments for polyline approximation
  • linetype (str) – linetype name, if not defined = BYLAYER
  • layer (str) – layer name
  • color (int) – range [1..255], 0 = BYBLOCK, 256 = BYLAYER

See also

Ellipse

DXFEngine.spline(points, segments=100, **kwargs)

Create a new cubic-spline-entity, curve shape is an approximation by POLYLINE.

Parameters:
  • points – breakpoints (knots) as 2D points (float-tuples), defines the curve, the curve goes through this points
  • segments (int) – count of line segments for polyline approximation
  • linetype (str) – linetype name, if not defined = BYLAYER
  • layer (str) – layer name
  • color (int) – range [1..255], 0 = BYBLOCK, 256 = BYLAYER

See also

Spline

DXFEngine.bezier(**kwargs)

Create a new cubic-bezier-entity, curve shape is an approximation by POLYLINE.

Parameters:
  • linetype (str) – linetype name, if not defined = BYLAYER
  • layer (str) – layer name
  • color (int) – range [1..255], 0 = BYBLOCK, 256 = BYLAYER

See also

Bezier

DXFEngine.clothoid(start=(0, 0), rotation=0., length=1., paramA=1.0, mirror="", segments=100, **kwargs)

Create a new clothoid-entity, curve shape is an approximation by POLYLINE.

Parameters:
  • start – insert point as 2D points (float-tuples)
  • rotation (float) – in degrees
  • length (loat) – length of curve in drawing units
  • paramA (float) – clothoid parameter A
  • mirror (str) – 'x' for mirror curve about x-axis, 'y' for mirror curve about y-axis, 'xy' for mirror curve about x- and y-axis
  • segments (int) – count of line segments for polyline approximation
  • linetype (str) – linetype name, if not defined = BYLAYER
  • layer (str) – layer name
  • color (int) – range [1..255], 0 = BYBLOCK, 256 = BYLAYER

See also

Clothoid