Skip to content
BadBit Documentation
Sign in Download the beta

BadBit CAD operations

cad.image.attach

Attaches an image or a PDF page (IMAGEATTACH, PDFATTACH).

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

Attaches the image (.png, .jpg, .tif, .bmp, .gif, .webp) or page page of the PDF (1 is the first) from file path, with the lower left corner at position, scale and rotation in degrees, like IMAGEATTACH and PDFATTACH. Returns what changed.

Parameters

NameTypeRequiredDescription
pageinteger | nullNoThe page: the page setup of a layout, or the PDF page (1 is the first).
pathstringYesThe absolute path of the file (of the drawing, or the one the operation reads or writes).
positionarray<number>YesPosition [x, y] of a point or of a text (the insertion point).
rotationnumber | nullNoRotation in degrees, counterclockwise.
scalenumber | nullNoThe scale: of an insertion, the same in X and Y; of a layout viewport, the denominator (50 is 1:50) or, in cad.viewport.modify, also the text ("1:50", "2:1").

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.
permission_denied-32002The request is not accepted (the detail says why).
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": {
        "path": "/Users/ana/Documents/BadBit/foto.png",
        "position": [
          0,
          0
        ],
        "scale": 10
      },
      "operation": "cad.image.attach"
    },
    "name": "badbit_call_operation"
  }
}

Python

Python
import badbit

result = badbit.cad.image.attach(path="/Users/ana/Documents/BadBit/foto.png", position=[0, 0], scale=10)

LISP

LISP
(badbit-call "cad.image.attach" '(("path" . "/Users/ana/Documents/BadBit/foto.png") ("position" . (0 0)) ("scale" . 10)))

JSON-RPC

JSON
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "badbit/call",
  "params": {
    "arguments": {
      "path": "/Users/ana/Documents/BadBit/foto.png",
      "position": [
        0,
        0
      ],
      "scale": 10
    },
    "operation": "cad.image.attach"
  }
}

Commands that do the same

IMAGEATTACHPDFATTACH

Full schema

JSON Schema 2020-12.

Parameters (input)
JSON
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "properties": {
    "page": {
      "default": null,
      "description": "The page: the page setup of a layout, or the PDF page (1 is the first).",
      "format": "uint",
      "maximum": 100000,
      "minimum": 1,
      "type": [
        "integer",
        "null"
      ]
    },
    "path": {
      "description": "The absolute path of the file (of the drawing, or the one the operation reads or writes).",
      "maxLength": 4096,
      "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"
    },
    "rotation": {
      "default": null,
      "description": "Rotation in degrees, counterclockwise.",
      "format": "double",
      "type": [
        "number",
        "null"
      ]
    },
    "scale": {
      "default": null,
      "description": "The scale: of an insertion, the same in X and Y; of a layout viewport, the denominator (50 is 1:50) or, in cad.viewport.modify, also the text (\"1:50\", \"2:1\").",
      "format": "double",
      "type": [
        "number",
        "null"
      ]
    }
  },
  "required": [
    "path",
    "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"
    },
    "truncated": {
      "description": "The lists were cut at the limit.",
      "type": "boolean"
    }
  },
  "required": [
    "created",
    "modified",
    "deleted",
    "document_changed",
    "truncated"
  ],
  "type": "object"
}
Search the documentation