Skip to content
BadBit Documentation
Sign in Download the beta

BadBit CAD operations

cad.draw.rectangle

Draws a rectangle (RECTANG) from two opposite corners.

  • Program: BadBit CAD
  • Type of action: Changes the drawing
  • Changes the drawing
  • Since version 2027.0.0-beta.8

Creates the closed polyline of the RECTANG command from corner1 to the opposite corner2, with the sides turned by rotation (degrees). Optional, as the command options: fillet (radius of rounded corners) or chamfer (the two distances), and polyline_width. On layer (it must exist) or on the current layer, with the current color and linetype. Returns the identifier. In paper space (a layout on screen, outside the viewports), the coordinates and the measures are in mm; angles and scale factors do not change.

Parameters

NameTypeRequiredDescription
chamferarray<number> | nullNoThe two chamfer distances of the corners [first, second].
corner1array<number>YesOne corner [x, y].
corner2array<number>YesThe opposite corner [x, y].
filletnumber | nullNoRadius of the rounded corners.
layerstring | nullNoLayer name.
polyline_widthnumber | nullNoWidth of the polyline.
rotationnumber | nullNoRotation in degrees, counterclockwise.

Errors

CodeJSON-RPCMeaning
invalid_params-32602The parameters do not follow the schema or a rule of the operation.
not_found-32001The object, operation, file or name does not exist.
conflict-32004The current state does not allow this now.
failed-32005The operation failed.

Example

MCP

JSON
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "arguments": {
        "corner1": [
          0,
          0
        ],
        "corner2": [
          12,
          8
        ]
      },
      "operation": "cad.draw.rectangle"
    },
    "name": "badbit_call_operation"
  }
}

Python

Python
import badbit

result = badbit.cad.draw.rectangle(corner1=[0, 0], corner2=[12, 8])

LISP

LISP
(badbit-call "cad.draw.rectangle" '(("corner1" . (0 0)) ("corner2" . (12 8))))

JSON-RPC

JSON
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "badbit/call",
  "params": {
    "arguments": {
      "corner1": [
        0,
        0
      ],
      "corner2": [
        12,
        8
      ]
    },
    "operation": "cad.draw.rectangle"
  }
}

Commands that do the same

RECTANG

Full schema

JSON Schema 2020-12.

Parameters (input)
JSON
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "properties": {
    "chamfer": {
      "default": null,
      "description": "The two chamfer distances of the corners [first, second].",
      "items": {
        "format": "double",
        "type": "number"
      },
      "maxItems": 2,
      "minItems": 2,
      "type": [
        "array",
        "null"
      ]
    },
    "corner1": {
      "description": "One corner [x, y].",
      "items": {
        "format": "double",
        "type": "number"
      },
      "maxItems": 2,
      "minItems": 2,
      "type": "array"
    },
    "corner2": {
      "description": "The opposite corner [x, y].",
      "items": {
        "format": "double",
        "type": "number"
      },
      "maxItems": 2,
      "minItems": 2,
      "type": "array"
    },
    "fillet": {
      "default": null,
      "description": "Radius of the rounded corners.",
      "format": "double",
      "type": [
        "number",
        "null"
      ]
    },
    "layer": {
      "default": null,
      "description": "Layer name.",
      "type": [
        "string",
        "null"
      ]
    },
    "polyline_width": {
      "default": null,
      "description": "Width of the polyline.",
      "format": "double",
      "type": [
        "number",
        "null"
      ]
    },
    "rotation": {
      "default": null,
      "description": "Rotation in degrees, counterclockwise.",
      "format": "double",
      "type": [
        "number",
        "null"
      ]
    }
  },
  "required": [
    "corner1",
    "corner2"
  ],
  "type": "object"
}
Result (output)
JSON
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "ids": {
      "description": "Object identifiers (32 hexadecimal digits each).",
      "items": {
        "type": "string"
      },
      "type": "array"
    }
  },
  "required": [
    "ids"
  ],
  "type": "object"
}
Search the documentation