Skip to content
BadBit Documentation
Sign in Download the beta

BadBit CAD operations

cad.annotate.field

Inserts a field (FIELD) in a multiline text.

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

Creates at position an MTEXT with the field code field_code (as AutoCAD stores it, %<\AcVar Date \f "dd/MM/yyyy">%; it may come inside a text), with the MTEXT height, style and attachment, and computes the value right away, like FIELD. 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
field_codestringYesThe field code (%<...>%), as AutoCAD stores it.
positionarray<number>YesPosition [x, y] of a point or of a text (the insertion point).

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": {
        "field_code": "%<\\AcVar Filename \\f \"%fn2\">%",
        "position": [
          0,
          0
        ]
      },
      "operation": "cad.annotate.field"
    },
    "name": "badbit_call_operation"
  }
}

Python

Python
import badbit

result = badbit.cad.annotate.field(field_code="%<\\AcVar Filename \\f \"%fn2\">%", position=[0, 0])

LISP

LISP
(badbit-call "cad.annotate.field" '(("field_code" . "%<\\AcVar Filename \\f \"%fn2\">%") ("position" . (0 0))))

JSON-RPC

JSON
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "badbit/call",
  "params": {
    "arguments": {
      "field_code": "%<\\AcVar Filename \\f \"%fn2\">%",
      "position": [
        0,
        0
      ]
    },
    "operation": "cad.annotate.field"
  }
}

Commands that do the same

FIELD

Full schema

JSON Schema 2020-12.

Parameters (input)
JSON
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "properties": {
    "field_code": {
      "description": "The field code (%<...>%), as AutoCAD stores it.",
      "maxLength": 10000,
      "minLength": 1,
      "type": "string"
    },
    "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"
    }
  },
  "required": [
    "position",
    "field_code"
  ],
  "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