Rectangle

Type: Composite Entity

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

DXFEngine.rectangle(insert, width, height, **kwargs)
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 (string) – target layer, default is '0'
  • linetype (string) – linetype name, None = BYLAYER

Example

import dxfwrite
from dxfwrite import DXFEngine as dxf

name="rectangle.dxf"
drawing = dxf.drawing(name)

for x in range(10):
    for y in range(10):
        color = 255 * random()
        bgcolor = 255 * random()
        rand = random()
        # rectangle with only backgound filling
        drawing.add(dxf.rectangle((x*3, y*3) , 1.5*rand, .7*rand,
                                  bgcolor=bgcolor))
        angle = 90 * random()
        # rectangle with only border lines
        drawing.add(dxf.rectangle((40+(x*3), y*3) , 1.5*rand, .7*rand,
                                  color=color, rotation=angle))
drawing.save()
print("drawing '%s' created.\n" % name)


../_images/rect.png