Skip to content

Script API ​

Scripts interact with the drawing through the cad object. Only members declared in CAD_SCRIPT_API_TREE can be accessed; all other properties will trigger an unknown_api error.

Execution Environment and Browser APIs ​

Scripts run in a strict-mode sandbox in the browser and can only access the cad object and ECMAScript standard built-in objects. They cannot manipulate the page DOM or make network requests.

Available built-in objects ​

All ECMAScript standard built-in objects are available:

  • Math and numbers: Math, Number, BigInt, parseFloat, parseInt, isNaN, isFinite
  • Data structures: Object, Array, Map, Set, WeakMap, WeakSet, Symbol
  • Text and formatting: String, JSON, RegExp, Intl, encodeURIComponent, decodeURIComponent
  • Time: Date (Date.now() can be used to measure the script's own execution time)
  • Others: Boolean, Promise, Error and its subclasses

Use cad.log() to output information instead of relying on console.log — the result panel only displays the content of cad.log.

Blocked browser APIs ​

The following are rejected outright during script validation, triggering forbidden_identifier / forbidden_syntax / forbidden_member errors. Object property keys such as { window: count } are allowed; free identifiers like window.foo are not.

  • Page and DOM: window, document, globalThis
  • Network and communication: fetch, XMLHttpRequest, WebSocket, importScripts
  • Device and environment: navigator, location, parent, top, self, frames (shadowed as undefined at runtime)
  • Storage: localStorage, sessionStorage
  • Dynamic execution: eval, Function
  • Other runtimes: process, require, module, exports, Deno, Bun
  • Syntax: import / export statements, dynamic import(), this, with, import.meta, super
  • Escape hatches: constructor, prototype, __proto__, __defineGetter__, __defineSetter__, __lookupGetter__, __lookupSetter__

WARNING

Besides the banned objects above, other browser globals (such as alert, setTimeout, performance, and console) may not be fully intercepted technically, but they are not part of the supported API. Scripts should rely only on the cad object and ECMAScript standard built-in objects; other accesses may be further restricted in future versions.

cad.drawing ​

Returns static information about the current drawing.

FieldTypeDescription
titlestringDrawing title
currentLayerstringCurrent layer name
unitsnumberInsertion units (INSUNITS)
layersArray<{ name, isOn, isFrozen, isLocked }>List of all layers
extents{ min: {x,y,z}, max: {x,y,z} } | undefinedModel space extents
javascript
const info = cad.drawing
cad.log('Current layer:', info.currentLayer)
cad.log('Total layers:', info.layers.length)

cad.entities ​

where / count / inBox scan model space and paper spaces only (not block definitions — use inBlock(id) for those). Attributes on a block reference follow that reference, and their ownerId is the reference. Every other entity's ownerId is the block table record that owns it. Block references use type === 'BlockReference'.

cad.entities.count(predicate) ​

Counts matches without building snapshots. Prefer this for tallies — where(pred).length still snapshots every match and can hit script_timeout on large drawings.

javascript
const n = cad.entities.count(e => e.type === 'Circle')

cad.entities.where(predicate) ​

Filters entity snapshots by a condition and returns an array of matching snapshots. Put filters in the predicate so only matches are snapshotted.

javascript
const circles = cad.entities.where(e => e.type === 'Circle')

cad.entities.byId(id) ​

Retrieves a single snapshot by entity ID, including entities outside model space. Returns undefined if not found.

javascript
const entity = cad.entities.byId('A1B2')
if (entity) {
  cad.log('Type:', entity.type, 'Owner:', entity.ownerId)
}

cad.entities.inBlock(blockId) ​

Snapshots entities stored directly in one block definition (or model/paper space). Prefer this over loading every block's entities.

javascript
const widget = cad.blocks.find(block => block.name === 'Widget')
const ents = widget ? cad.entities.inBlock(widget.id) : []

cad.entities.inBox(min, max) ​

Returns snapshots whose world extents intersect the given rectangle (model and paper spaces only).

javascript
const inside = cad.entities.inBox({ x: 0, y: 0 }, { x: 100, y: 100 })

Entity Snapshot (EntitySnapshot) ​

FieldTypeDescription
idstringEntity object ID
ownerIdstringOwning block table record ID, or the block reference ID for an attribute
typestringEntity type, without the AcDb prefix, e.g. Circle, Line
layerstringLayer name the entity resides on
colorEntityColorStored color, before ByLayer / ByBlock resolution
resolvedColorEntityColorColor with ByLayer / ByBlock already resolved
lineTypestringLinetype name (ByLayer / ByBlock are kept as stored)
lineWeightnumberAcGiLineWeight value; negative values mean ByLayer / ByBlock
linetypeScalenumberLinetype scale factor
visibilitybooleanfalse when the entity is hidden
transparencyEntityTransparencyTransparency method plus alpha
thicknessnumber | undefinedExtrusion thickness, when the type has one
normal{x,y,z} | undefinedExtrusion / plane normal, when the type has one
extents{ min: {x,y,z}, max: {x,y,z} } | undefinedWorld coordinate system extents
geometryobject | undefinedType-specific geometry data

EntityColor is { red?, green?, blue?, hex?, colorIndex?, isByColor, isByACI, isByLayer, isByBlock, isForeground }. ByLayer / ByBlock colors carry no RGB; read resolvedColor when an actual color is needed. EntityTransparency is { method, alpha, percentage?, isByAlpha, isByLayer, isByBlock }.

Display properties are read lazily inside cad.entities.where(...) predicates: only the fields a predicate touches are resolved, and only matching entities are converted into full snapshots.

geometry is filled for every concrete entity type in @mlightcad/data-model. Common fields:

Entity Typegeometry Fields
Circle{ center, radius, area, circumference, closed }
Line{ start, end, length, midPoint, direction, closed }
Arc{ center, radius, startAngle, endAngle, startAngleDeg, endAngleDeg, length, area, startPoint, endPoint, midPoint, closed }
Ellipse{ center, majorAxis, majorRadius, minorRadius, startAngle, endAngle, startAngleDeg, endAngleDeg, area, isCircular, closed }
Polyline{ points, vertices: [{ bulge, startWidth, endWidth }], bulges, hasBulges, hasWidths, closed, elevation, length, area }
2dPolyline{ points, vertices, bulges, hasBulges, closed, polyType, elevation, length, area }
3dPolyline{ points, closed, polyType, length }
Spline{ points, controlPoints, fitPoints, knots, weights, degree, length, area, isFitPointSpline, isControlPointSpline, startPoint, endPoint, closed, normal }
Point / 2dVertex / 3dVertex{ position }, plus ecsRotation for Point
Ray / Xline{ basePoint, unitDir }
Text{ position, text, height, rotation, styleName, alignmentPoint, hasAlignmentPoint, oblique, obliqueDeg, horizontalMode, verticalMode, widthFactor, isBackward, isUpsideDown }
MText{ position, text, plainText, height, width, extentsWidth, rotation, styleName, attachmentPoint, direction, lineSpacingFactor, lineSpacingStyle, backgroundFill, backgroundFillColor, backgroundScaleFactor, drawingDirection, columnType, columnCount, columnWidth, columnGutter, columnFlowReversed }
AttributeText fields plus { tag, invisible, isMTextAttribute, mtextContents }
AttributeDefinitionText fields plus { tag, prompt, invisible }
ArcAlignedText{ text, height, center, radius, startAngle, endAngle, startAngleDeg, endAngleDeg, styleName, arcId, xScale, characterSpacing, offsetFromArc, leftOffset, rightOffset, alignment, isReverse }
BlockReference{ name, effectiveName, isDynamicBlock, position, rotation, scale, columnCount, rowCount, columnSpacing, rowSpacing, blockTransform, attributes: [{ tag, text, position, invisible }] }
TableInsert fields plus { rows, columns, attachmentPoint, rowHeights, columnWidths, tableWidth, tableHeight, cells }
Hatch{ patternName, patternType, patternAngle, patternScale, patternDouble, hatchStyle, isSolidFill, isHatch, isGradient, backgroundColor, elevation, associative, area, gradientAngle, gradientShift, gradientType, gradientName, gradientOneColorMode, shadeTintValue, gradientStartColor, gradientEndColor, boundary, loops: [{ closed, points, length }] }
Leader{ vertices, dimensionStyle, hasArrowHead, hasHookLine, isSplined, numVertices, textHeight, textWidth, annoType, associatedAnnotation }
MLeader{ contents, textLocation, textHeight, textWidth, textRotation, landingPoint, contentType, numberOfLeaders, doglegLength, doglegEnabled, leaderLineType, leaderLineColor, leaders: [{ vertices, lastLeaderLinePoint, landingPoint }] }
MLine{ styleName, scale, justification, closed, startPosition, vertices }
Solid / Trace / Face{ points, area }
PolyFaceMesh{ vertices, faces }
PolygonMesh{ mCount, nCount, closedM, closedN, vertices }
RasterImage / Wipeout{ position, rotation, width, height, imageSize, scale, clipBoundary, clipBoundaryType, brightness, contrast, fade, isImageShown, isImageTransparent, imageFileName, imageDisplayName, isClipped }
Ole2Frame{ upperLeft, lowerRight, userType, oleObjectType }
Viewport{ number, center, width, height, viewCenter, viewTarget, viewDirection, viewHeight, viewTwistAngle, sheetName, status, frozenLayerIds }
Shape{ name, position, size, rotation, styleName, shapeNumber, widthFactor, oblique, isPlanar }
Fcf{ position, text, dimensionStyle, textHeight, direction, annotative }
3dSolid{ version, guid, hasRenderableGeometry }. ACIS body data is omitted
ProxyEntity{ originalDxfName, originalClassName, applicationName }. Proxy graphics bytes are omitted
Dimension types{ text, annotationText, measurement, dimensionType, textPosition, styleName, rotation, horizontalRotation, horizontalRotationDeg, attachmentPoint, textLineSpacingFactor, textLineSpacingStyle, normal } plus definition points such as xLine1Point, chordPoint, or definingPoint

Points are { x, y, z }. startAngle / endAngle are radians. startAngleDeg / endAngleDeg are degrees. plainText has MTEXT formatting codes (\P, \fSimSun|b0|i0;, braces) stripped, so it can be searched directly. measurement on a dimension is computed from the definition points when the entity holds no stored value.

cad.tables ​

Read-only access to every symbol table, matching AcDbDatabase.tables. Each table is { id, records }. Every record has at least id and name, plus fields for that table.

PropertyContents
appIdTableRegistered application names
blockTableBlock table records. Definitions only; load entities with cad.entities.inBlock(id)
dimStyleTableDimension styles, including variables such as dimtxt and dimscale
linetypeTableLinetypes: numDashes, patternLength, comments
textStyleTableText styles: fileName, textSize, xScale
ucsTableNamed UCSs: origin, xAxis, yAxis
viewTableNamed views
layerTableLayers: color, linetype, lineWeight, isOff, isFrozen, isLocked, isPlottable
viewportTableModel-space VPORT records (*Active and named views), not paper-space Viewport entities
javascript
const layers = cad.tables.layerTable.records
  .filter(record => !record.isOff)
  .map(record => record.name)
return layers

A layer color is { red, green, blue, colorIndex, isByACI, isByLayer, isByBlock }.

cad.blocks ​

Returns every block definition as metadata only (same role as a DXF BLOCKS section). *Model_Space and each *Paper_Space are included. Entity geometry is not embedded — use cad.entities.inBlock(id) when needed. Eagerly snapshotting every block timed out on large drawings.

FieldTypeDescription
idstringBlock table record ID. Also the ownerId of entities in the block
namestringBlock name
origin{ x, y, z }Base point
isModelSpacebooleanTrue for model space
isPaperSpacebooleanTrue for a paper-space layout block
flagsnumberBLOCK group code 70
pathNamestringXref path. Empty for a local block
isXrefbooleanTrue when the block is an external reference
layoutIdstring | undefinedAssociated layout ID
entityCountnumberNumber of entities stored in the block (no snapshots)
typeCountsRecord<string, number>Counts by entity type inside the block (no snapshots)
javascript
const widget = cad.blocks.find(block => block.name === 'Widget')
const ents = widget ? cad.entities.inBlock(widget.id) : []
return {
  count: widget ? widget.entityCount : 0,
  types: ents.map(entity => entity.type)
}

cad.selection ​

Used to highlight and select entities.

cad.selection.ids ​

The currently selected entity IDs. This is a property, not a method.

javascript
const ids = cad.selection.ids

cad.selection.entities ​

Snapshots of every entity in the selection set. Ids that no longer exist are omitted. Each snapshot has the same fields as cad.entities.byId, including ownerId.

javascript
const circles = cad.selection.entities.filter(e => e.type === 'Circle')

cad.selection.replace(ids) ​

Clears the selection set and replaces it with the specified ID list.

javascript
cad.selection.replace(circles.map(e => e.id))

cad.selection.add(ids) ​

Adds the specified IDs to the current selection set.

javascript
cad.selection.add(['A1B2', 'C3D4'])

cad.selection.remove(ids) ​

Removes the specified IDs from the current selection set.

javascript
cad.selection.remove(['A1B2'])

cad.selection.clear() ​

Clears the selection set.

javascript
cad.selection.clear()

cad.view ​

Used to control the view.

cad.view.zoomExtents() ​

Zooms the view to the model space extents.

javascript
cad.view.zoomExtents()

cad.view.capturePreview({ longSide?, selection?, layers? }) ​

Queues a PNG screenshot after the script body finishes. Returns { queued: true, index }. Default frames model-space drawing extents. Pass selection: true (typically after cad.selection.replace(ids)) to extract only the current selection via the ENTPREVIEW batch path. Pass layers (a layer name or an array of names, case-insensitive) to render only the model-space geometry on those layers, framed to the combined extents of those layers rather than the whole drawing, so the image has no large empty margins. Layer on/off state is ignored; unknown layer names throw; layers cannot be combined with selection. In the Agent chat, images are attached to the tool result for the model (not returned as JSON data URLs).

javascript
cad.view.zoomExtents()
cad.view.capturePreview()
// optional: cad.view.capturePreview({ longSide: 512 })
// selection only: cad.view.capturePreview({ selection: true })
// layers only: cad.view.capturePreview({ layers: ['WALL', 'DOOR'] })

cad.file ​

Exports the current drawing. File bodies are not returned to the script or the model; the tool result lists savedFiles summaries only.

cad.file.saveDxf(path?) ​

Queues a DXF export that runs after the script succeeds. Pass a path string or { path?, fileName? }. .dxf is appended when the extension is missing. Returns { queued: true, index, fileName }.

  • In the in-app agent and the script panel, this starts a browser download.
  • In cad-mcp-server, the server writes path on disk. Relative paths resolve from the server process working directory. The tool result lists savedFiles with the absolute path and byte size.
javascript
cad.file.saveDxf('./plan-out.dxf')
// or: cad.file.saveDxf({ path: './plan-out.dxf' })

cad.file.savePdf(path?) ​

Queues a PDF export that runs after the script succeeds. Pass a path string or { path?, fileName?, exportLayouts?, exportEmptyLayouts?, colorMode?, textMode?, modelSpaceFit? }. .pdf is appended when missing. Defaults: exportLayouts: true, exportEmptyLayouts: false, colorMode: 'color', textMode: 'text', modelSpaceFit: 'extents'. Returns { queued: true, index, fileName }.

Delivery matches saveDxf (browser download or MCP disk write).

javascript
cad.file.savePdf('./plan.pdf')
// or: cad.file.savePdf({ path: './plan.pdf', colorMode: 'monochrome' })

cad.file.saveHtml(path?) ​

Queues an offline HTML export (or a multi-file .zip package) after the script succeeds. Pass a path string or { path?, fileName?, exportFormat?, exportLayouts?, exportEmptyLayouts?, background? }. Defaults include exportLayouts: true and exportEmptyLayouts: false.

  • exportFormat: 'single' (default, .html) or 'multi' (.zip)
  • background: 'black', 'white', or 'space' (default)

Requires a viewer host that provides CadSession.exportHtml (in-app agent / cad-mcp-server). Headless createDatabaseSession skips the request with a log note. Returns { queued: true, index, fileName }.

javascript
cad.file.saveHtml('./plan.html')
// or: cad.file.saveHtml({ path: './plan.zip', exportFormat: 'multi' })

cad.measure ​

Numeric helpers for self-check after drawing. Prefer these over hand-rolled Math.hypot / atan2. Points are { x, y } in WCS.

MethodReturns
cad.measure.distance(a, b)Distance between two points
cad.measure.angleDeg(a, b)Bearing of a→b from +X, degrees in (-180, 180]
cad.measure.angleDeg(a, b, c)Interior angle at b (a–b–c), degrees in [0, 180]
cad.measure.deltaAngleDeg(fromDeg, toDeg)Smallest absolute bearing difference in [0, 180]
cad.measure.center(id)Circle/arc/ellipse center, or point/text position; else undefined
cad.measure.radius(id)Circle/arc radius or ellipse majorRadius; else undefined
cad.measure.length(id)Line length, or polyline/spline/2dPolyline/3dPolyline path length; else undefined
cad.measure.area(id)Area reported by the entity, or polygon area of its boundary points; else undefined
cad.measure.check(name, expected, actual, tolerance?){ name, expected, actual, pass } (default tolerance 1e-3)
cad.measure.report(checks){ ok, checks } — ok is true iff every check passed

Recommended return shape after a non-trivial draw:

javascript
const origin = { x: 0, y: 0 }
let circleId = ''
cad.edit.transaction('draw', tx => {
  circleId = tx.drawCircle({ center: { x: 30, y: 40 }, radius: 10 })
})
const center = cad.measure.center(circleId)
return {
  ...cad.measure.report([
    cad.measure.check('r', 10, cad.measure.radius(circleId)),
    cad.measure.check('pcd', 50, cad.measure.distance(origin, center), 0.01)
  ]),
  entityIds: [circleId]
}

cad.redraw ​

Evidence-tracked reconstruction of a drawing from a reference image (scan, photo, screenshot). The script builds a plain spec object; cad.redraw validates it, draws it in one undo group on standard layers (OBJECT, HIDDEN, CENTER, DIM, TEXT, TABLE, BORDER, CONSTRUCTION, ASSUMPTION), and inspects the result. The full spec reference is exported as CAD_REDRAW_SPEC_SUMMARY and embedded in the agent prompt.

MethodDescription
cad.redraw.validate(spec, { profile? }?)Checks fields, ids, units, calibration, and constraints without drawing → { status, errors, warnings, evidence, calibrations }
cad.redraw.draw(spec, { profile?, omit?, offset?, allowBlocked? }?)Draws the spec → { status, drawn, idMap, entityCount, skipped, checks, dimensionChecks, errors, warnings }
cad.redraw.inspect(spec, idMap, { profile? }?)Re-runs checks and compares dimension value readings with what the drawn dimensions measure
cad.redraw.compare(spec, { referenceIndex?, calibration?, viewId?, tolerancePx?, maxSide?, images? }?)Pixel comparison with the attached reference image: registers the rendered drawing through the spec calibration and returns redrawCompare (verdict, coverage, precision, distances, suggestedMove, hotspots) plus overlay and difference images
  • Profiles: general (default), strict-dimensioned, hybrid, visual-trace, geometry-only (skips text, dimensions, leaders, and table text).
  • Evidence per value: known, scaled, inferred, unreadable. Units default to unitless; millimeters are never assumed.
  • Entities use CAD coordinates by default. With coords: 'source' they are image pixels (top-left origin, y down) mapped by a calibration (dimension-anchor, similarity, affine, homography, sheet-scale).
  • Status: pass, pass_with_warnings, needs_review (dimension or constraint conflicts), blocked (strict profile lacks evidence), fail (invalid spec; nothing is drawn).
  • Tables are drawn as lines and text, not as an AcDbTable.
  • Drawing sets INSUNITS from units, puts text and dimension text on the CJK-capable REDRAW_TEXT style (simsun + hztxt.shx), and draws a dimension that cannot be created as lines and text (radius/diameter as a leader) with a warning; fallbacks counts them.
javascript
const r = cad.redraw.draw({
  profile: 'general',
  units: 'mm',
  entities: [
    { id: 'plate', type: 'rectangle', x: 0, y: 0, width: 120, height: 80, evidence: 'known' },
    { id: 'hole', type: 'circle', center: [60, 40], radius: 10, evidence: 'known' },
    { id: 'w', type: 'linear_dimension', p1: [0, 0], p2: [120, 0], dimLine: [60, -12], value: 120, evidence: 'known' },
    { id: 'note', type: 'leader', points: [[67, 47], [85, 65], [95, 65]], text: 'THRU' }
  ],
  checks: [{ measure: 'radius', entity: 'hole', expected: 10 }]
})
return { status: r.status, checks: r.checks, dimensionChecks: r.dimensionChecks }

Pixel comparison ​

cad.redraw.compare renders the drawing over the CAD footprint of the reference (or of views[].sourceRoi), warps it into the image frame through the calibration (similarity, affine, or homography), thins both to 1-pixel centerlines, and measures them against each other with distance transforms.

  • coverage: share of reference lines with drawn geometry within tolerance (missing geometry lowers it).
  • precision: share of drawn lines with a reference line within tolerance (extra or misplaced geometry lowers it).
  • meanDistance* / p95Distance*: how far reference lines are from the drawing, in reference pixels and CAD units.
  • verdict: aligned, offset (a translation fixes most of it — see suggestedMove), incomplete, cluttered, or mismatch.
  • hotspots: the grid cells with the most disagreement, as sourceRoi (image pixels) and cadBox.

The overlay shows the faded reference with matched lines in green, missing lines in red, and extra lines in blue. Comparison needs a renderer and an attached image, so it works in the in-app agent; headless sessions return reason: 'no_raster_host'. Pixel metrics are visual evidence only and never prove dimensions.

cad.edit.transaction ​

Executes edit operations. All modifications are grouped as a single undo unit. The drawing must be in an editable state (not read-only mode).

javascript
cad.edit.transaction('Batch modify', tx => {
  tx.drawCircle({ center: { x: 50, y: 50 }, radius: 10, layer: '0' })
  tx.move(entityIds, 10, 20)
})

Methods available within a transaction:

Drawing Methods ​

MethodParametersReturn Value
tx.drawLine({ start, end, layer? })start/end: {x,y}New entity ID
tx.drawCircle({ center, radius, layer? })center: {x,y}New entity ID
tx.drawArc({ center, radius, startAngleDeg, endAngleDeg, layer? })center: {x,y}New entity ID
tx.drawRectangle({ corner1, corner2, layer? })corner1/corner2: {x,y}New entity ID
tx.drawPolyline({ points, closed?, layer? })points: Array<{x,y}>New entity ID
tx.drawEllipse({ center, majorRadius, minorRadius, rotationDeg?, startAngleDeg?, endAngleDeg?, layer? })center: {x,y}New entity ID
tx.drawHatch({ boundary, patternName?, patternScale?, patternAngleDeg?, layer? })boundary: Array<{x,y}> (min 3)New entity ID
tx.drawPoint({ position, layer? })position: {x,y}New entity ID
tx.drawRay({ start, through, layer? })start/through: {x,y}New entity ID
tx.drawXline({ start, through, layer? })start/through: {x,y}New entity ID
tx.drawSpline({ points, closed?, layer? })points: Array<{x,y}>New entity ID
tx.drawText({ position, text, height?, rotationDeg?, width?, layer? })position: {x,y}New entity ID
tx.drawDimAligned({ xLine1Point, xLine2Point, dimLinePoint, text?, styleName?, layer? })points {x,y}New entity ID
tx.drawDimLinear({ xLine1Point, xLine2Point, dimLinePoint, rotationDeg?, text?, styleName?, layer? })omit rotationDeg → H/V by placementNew entity ID
tx.drawDimDiameter({ center, radius, angleDeg?, leaderLength?, … } | { chordPoint, farChordPoint, … })circle form or chord formNew entity ID
tx.drawDimRadius({ center, radius, angleDeg?, leaderLength?, … } | { center, chordPoint, … })circle form or chord formNew entity ID
tx.drawDimAngular({ center, xLine1Point, xLine2Point, arcPoint, text?, styleName?, layer? })3-point angleNew entity ID
tx.drawDimArc({ center, xLine1Point, xLine2Point, arcPoint, text?, styleName?, layer? })arc lengthNew entity ID
tx.drawDimOrdinate({ definingPoint, leaderEndPoint, useXAxis?, origin?, text?, styleName?, layer? })X/Y ordinateNew entity ID
tx.drawLeader({ points, text?, textPosition?, textHeight?, textLayer?, arrowHead?, styleName?, layer? })arrow at points[0]Leader ID (annotation MTEXT id is also in created ids)

Use drawDim* for true dimension entities. Do not fake dimensions with lines, arrows, and text. Style defaults to the drawing $DIMSTYLE; pass styleName from cad.tables.dimStyleTable to override.

Edit Methods ​

MethodParametersReturn Value
tx.erase(ids)string[]Number of entities erased
tx.setLayer(ids, layer)string[], string—
tx.move(ids, dx, dy)string[], number, numberNumber of entities moved
tx.rotate(ids, center, angleDeg)string[], {x,y}, numberNumber of entities rotated
tx.createLayer(name)string—
tx.setCurrentLayer(name)string—

cad.log ​

Outputs log messages to the result panel.

javascript
cad.log('Entity count:', count)
cad.log({ layer: '0', count })

Return Values ​

Scripts can use return to return any JSON-serializable value. The return value is displayed in the result panel.

javascript
return {
  total: all.length,
  circles: circles.length,
  onLayer0: onLayer0.length
}

If the return value exceeds 65536 characters, it will be truncated and marked as truncated.