Skip to content
BadBit Documentation
Sign in Download the beta

BadBit CAD operations

cad.draw.attdef

Creates an attribute definition (-ATTDEF).

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

Creates the attribute definition tag (no spaces) at position, with the prompt attribute_prompt and the default value default_value, like -ATTDEF: height, rotation in degrees, style (text style), justify (L, C, R, M, TL, TC, TR, ML, MC, MR, BL, BC or BR) and modes (invisible, constant, verify, preset, lock_position, multiline); what is not given stays as the command remembers. Put it in a block with cad.draw.block. Returns what changed. 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
attribute_promptstringNoThe prompt shown when the block is inserted.
default_valuestringNoThe default value of the attribute.
heightnumber | nullNoText height; in zoom, the visible height; in images, the height in pixels; in a named view, in drawing units; in a layout viewport, the height of the model it shows, in drawing units.
justifyTextJustify | nullNoThe text justification: L, C, R, M, TL, TC, TR, ML, MC, MR, BL, BC or BR.
modesarray<AttMode> | nullNoThe attribute modes: invisible, constant, verify, preset, lock_position and multiline.
positionarray<number>YesPosition [x, y] of a point or of a text (the insertion point).
rotationnumber | nullNoRotation in degrees, counterclockwise.
stylestring | nullNoText style name (it must exist in the drawing).
tagstringYesThe attribute tag (no spaces).
widthnumber | nullNoThe width: of an image, in pixels (64 to 2048, default 1024); of a named view, in drawing units.

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": {
        "attribute_prompt": "Room name",
        "default_value": "Kitchen",
        "height": 2.5,
        "position": [
          0,
          0
        ],
        "tag": "ROOM"
      },
      "operation": "cad.draw.attdef"
    },
    "name": "badbit_call_operation"
  }
}

Python

Python
import badbit

result = badbit.cad.draw.attdef(attribute_prompt="Room name", default_value="Kitchen", height=2.5, position=[0, 0], tag="ROOM")

LISP

LISP
(badbit-call "cad.draw.attdef" '(("attribute_prompt" . "Room name") ("default_value" . "Kitchen") ("height" . 2.5) ("position" . (0 0)) ("tag" . "ROOM")))

JSON-RPC

JSON
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "badbit/call",
  "params": {
    "arguments": {
      "attribute_prompt": "Room name",
      "default_value": "Kitchen",
      "height": 2.5,
      "position": [
        0,
        0
      ],
      "tag": "ROOM"
    },
    "operation": "cad.draw.attdef"
  }
}

Commands that do the same

-ATTDEFATTDEF

Full schema

JSON Schema 2020-12.

Parameters (input)
JSON
{
  "$defs": {
    "AttMode": {
      "oneOf": [
        {
          "const": "invisible",
          "type": "string"
        },
        {
          "const": "constant",
          "type": "string"
        },
        {
          "const": "verify",
          "type": "string"
        },
        {
          "const": "preset",
          "type": "string"
        },
        {
          "const": "lock_position",
          "type": "string"
        },
        {
          "const": "multiline",
          "type": "string"
        }
      ]
    },
    "TextJustify": {
      "oneOf": [
        {
          "const": "L",
          "type": "string"
        },
        {
          "const": "C",
          "type": "string"
        },
        {
          "const": "R",
          "type": "string"
        },
        {
          "const": "M",
          "type": "string"
        },
        {
          "const": "TL",
          "type": "string"
        },
        {
          "const": "TC",
          "type": "string"
        },
        {
          "const": "TR",
          "type": "string"
        },
        {
          "const": "ML",
          "type": "string"
        },
        {
          "const": "MC",
          "type": "string"
        },
        {
          "const": "MR",
          "type": "string"
        },
        {
          "const": "BL",
          "type": "string"
        },
        {
          "const": "BC",
          "type": "string"
        },
        {
          "const": "BR",
          "type": "string"
        }
      ]
    }
  },
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "properties": {
    "attribute_prompt": {
      "default": "",
      "description": "The prompt shown when the block is inserted.",
      "type": "string"
    },
    "default_value": {
      "default": "",
      "description": "The default value of the attribute.",
      "type": "string"
    },
    "height": {
      "default": null,
      "description": "Text height; in zoom, the visible height; in images, the height in pixels; in a named view, in drawing units; in a layout viewport, the height of the model it shows, in drawing units.",
      "format": "double",
      "type": [
        "number",
        "null"
      ]
    },
    "justify": {
      "anyOf": [
        {
          "$ref": "#/$defs/TextJustify"
        },
        {
          "type": "null"
        }
      ],
      "description": "The text justification: L, C, R, M, TL, TC, TR, ML, MC, MR, BL, BC or BR."
    },
    "modes": {
      "description": "The attribute modes: invisible, constant, verify, preset, lock_position and multiline.",
      "items": {
        "$ref": "#/$defs/AttMode"
      },
      "maxItems": 6,
      "type": [
        "array",
        "null"
      ]
    },
    "position": {
      "description": "Position [x, y] of a point or of a text (the insertion point).",
      "items": {
        "format": "double",
        "type": "number"
      },
      "maxItems": 2,
      "minItems": 2,
      "type": "array"
    },
    "rotation": {
      "default": null,
      "description": "Rotation in degrees, counterclockwise.",
      "format": "double",
      "type": [
        "number",
        "null"
      ]
    },
    "style": {
      "default": null,
      "description": "Text style name (it must exist in the drawing).",
      "type": [
        "string",
        "null"
      ]
    },
    "tag": {
      "description": "The attribute tag (no spaces).",
      "maxLength": 255,
      "minLength": 1,
      "type": "string"
    },
    "width": {
      "default": null,
      "description": "The width: of an image, in pixels (64 to 2048, default 1024); of a named view, in drawing units.",
      "format": "double",
      "type": [
        "number",
        "null"
      ]
    }
  },
  "required": [
    "tag",
    "position"
  ],
  "type": "object"
}
Result (output)
JSON
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "created": {
      "description": "Identifiers of the objects created.",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "deleted": {
      "description": "The identifiers of what was deleted.",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "document_changed": {
      "description": "The drawing on screen is another one (opened, closed or changed tab): the lists of changes do not apply.",
      "type": "boolean"
    },
    "modified": {
      "description": "Whether there are unsaved changes; in results of changes, the identifiers of the objects changed.",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "skipped_locked": {
      "description": "Objects left as they were because they are on locked layers.",
      "format": "uint",
      "minimum": 0,
      "type": "integer"
    },
    "truncated": {
      "description": "The lists were cut at the limit.",
      "type": "boolean"
    }
  },
  "required": [
    "created",
    "modified",
    "deleted",
    "document_changed",
    "truncated"
  ],
  "type": "object"
}
Search the documentation