Skip to content

Command Reference

This page documents all script commands available in LoomCAD.


Command Syntax

All commands follow this pattern:

javascript
runScriptCommand("commandName", { options });
  • Commands execute synchronously
  • Options are passed as an object
  • Most commands have required and optional parameters
  • Returns { success: boolean, elements: [...], error?: string }

Execution Model

Scripts run synchronously. All changes are applied only after the entire script completes. There is no async/await support.


Draw Commands

Create new elements on the canvas.

drawComponent

Creates a component (connector, terminal, device).

javascript
runScriptCommand("drawComponent", {
  position: { x: 200, y: 300 }, // Required: Position on canvas
  pinNumberingOrder: "column", // Required: 'column' or 'row'
  flipped: false, // Required: Flip orientation
  compElementData: {
    // Required: Component metadata
    name: "J101", // Required: Component name
    partnumber: "MOLEX-123", // Required: Part number
    pinCount: 8, // Required: Number of pins
  },
  pinData: {
    // Required: Pin configuration
    x: 1, // Horizontal pin count
    y: 8, // Vertical pin count
    pins: [
      // Required: Array of pin definitions
      { name: "1", partnumber: "" },
      { name: "2", partnumber: "" },
      // ... one entry for each pin
    ],
  },
});

Simplified example (minimum required):

javascript
// Create 8-pin connector with auto-generated pin names
const pins = [];
for (let i = 1; i <= 8; i++) {
  pins.push({ name: String(i), partnumber: "" });
}

runScriptCommand("drawComponent", {
  position: { x: 200, y: 300 },
  pinNumberingOrder: "column",
  flipped: false,
  compElementData: {
    name: "J101",
    partnumber: "MOLEX-123",
    pinCount: 8,
  },
  pinData: { x: 1, y: 8, pins },
});

drawLibraryComponent

Creates a component from a library.

javascript
runScriptCommand("drawLibraryComponent", {
  libraryId: "lib-123", // Library component ID
  name: "ECU1", // Name for the new instance
  x: 200,
  y: 300,
});

createLibraryComponent

Creates a new component in a library project. A new sheet is added to the library and the component is drawn on it.

javascript
runScriptCommand("createLibraryComponent", {
  libraryProject: libraryProject, // Required: Library project object
  pinData: {
    // Required: Pin layout
    x: 1, // Horizontal pin count
    y: 8, // Vertical pin count
    pins: [
      { name: "1", partnumber: "" },
      // ... one entry per pin
    ],
  },
  compElementData: {
    // Required: Component properties
    name: "J1",
    partnumber: "MOLEX-123",
    pinCount: 8,
  },
  flipped: false, // Required: Orientation
  pinNumberingOrder: "column", // Required: 'column' or 'row'
  position: { x: 200, y: 300 }, // Required: Position on sheet
  usePartNumber: true, // Optional: Use partnumber as sheet name
  sheetName: "NewComponent", // Optional: Fallback sheet name
  sideViewData: null, // Optional: Sideview image/SVG data
});

When usePartNumber is true, the library sheet is named after the component's part number. Otherwise the sheetName value is used (defaults to "NewComponent").

drawWire

Creates a wire connection between pins.

javascript
runScriptCommand("drawWire", {
  start: {
    // Required: Source pin
    componentName: "ECU1", // Component name
    pinName: "1", // Pin name (string)
  },
  end: {
    // Required: Destination pin
    componentName: "J101",
    pinName: "3",
  },
  name: "PWR_MAIN", // Required: Wire name
  partnumber: "WIRE-18AWG-RED", // Required: Part number
  colors: ["red"], // Optional: DIN 47100 color(s)
  coreSizeAWG: "18", // Optional: Wire gauge
});

Alternative: Pin by index (1-based):

javascript
runScriptCommand("drawWire", {
  start: { componentName: "ECU1", pinIndex: 1 }, // First pin
  end: { componentName: "J101", pinIndex: 3 }, // Third pin
  name: "PWR_MAIN",
  partnumber: "WIRE-18AWG-RED",
});

Color values: white, brown, green, yellow, grey, pink, blue, red, black, violet, orange

Two-color (stripe): Use array ['red', 'blue'] for stripe combinations.

drawBundle

Creates a bundle segment between two points, optionally with bend points.

javascript
runScriptCommand("drawBundle", {
  start: { x: 100, y: 200 }, // Required: Start point
  end: { x: 300, y: 200 }, // Required: End point
  name: "MAIN_TRUNK", // Required: Bundle name
  partnumber: "BUNDLE-001", // Required: Part number
  bendPoints: [
    // Optional: intermediate bend points
    { x: 150, y: 250 },
    { x: 250, y: 250 },
  ],
});

Multi-segment bundles

Use the bendPoints parameter to create a bundle with multiple segments in one command. The bundle path goes: start → bend1 → bend2 → ... → end.

tubingType values (set via updateBundle):

  • heatshrink, coldshrink, sleeving
  • braidedsleeving, solid, wireloom
  • conduit, pvccoated

drawLine

Creates a decorative line (not electrical).

javascript
runScriptCommand("drawLine", {
  start: { x: 100, y: 100 },
  end: { x: 300, y: 100 },
  style: {
    strokeWidth: 2,
    strokeColor: "#000000",
    dashArray: [10, 5], // Optional: dashed line
  },
});

drawCircle

Creates a circle shape.

javascript
runScriptCommand("drawCircle", {
  center: { x: 200, y: 200 },
  radius: 50,
  style: {
    strokeWidth: 1,
    strokeColor: "#000000",
    fillColor: "#ffffff",
  },
});

drawRectangle

Creates a rectangle shape.

javascript
runScriptCommand("drawRectangle", {
  start: { x: 100, y: 100 },
  end: { x: 300, y: 250 },
  style: {
    strokeWidth: 1,
    strokeColor: "#000000",
    fillColor: "#f0f0f0",
  },
});

drawText

Creates a text annotation.

javascript
runScriptCommand("drawText", {
  position: { x: 100, y: 50 },
  text: "Power Distribution",
  fontSize: 14,
  style: {
    color: "#000000",
    fontFamily: "Arial",
    fontWeight: "bold",
    isItalic: false,
  },
});

drawDimension

Creates a dimension annotation.

javascript
runScriptCommand("drawDimension", {
  x1: 100,
  y1: 200, // Start point
  x2: 400,
  y2: 200, // End point
  offset: 30, // Distance from line
});

drawImage

Places an image on the canvas.

javascript
runScriptCommand("drawImage", {
  src: "data:image/png;base64,...", // Image data or URL
  x: 100,
  y: 100,
  width: 200, // Optional
  height: 150, // Optional
});

drawSVG

Places an SVG graphic.

javascript
runScriptCommand("drawSVG", {
  svg: "<svg>...</svg>", // SVG content
  x: 100,
  y: 100,
});

drawBundleBreak

Adds a break point to a bundle.

javascript
runScriptCommand("drawBundleBreak", {
  bundleName: "MAIN_TRUNK",
  offset: 0.5, // Position along bundle (0.0 = start, 1.0 = end)
});

addBundleBend

Adds a bend (corner) to a bundle, splitting it into two segments.

javascript
runScriptCommand("addBundleBend", {
  bundleName: "MAIN_TRUNK",
  point: { x: 250, y: 200 }, // Point ON the bundle line
});

Calculating the point: The point must lie on the bundle segment:

point.x = start.x + k * (end.x - start.x)
point.y = start.y + k * (end.y - start.y)

where k is between 0 and 1 (e.g., 0.5 = midpoint). The point is projected onto the segment and clamped to the 5%–95% range.

removeBundleBend

Removes a bend from a bundle, merging two adjacent segments back into one.

javascript
runScriptCommand("removeBundleBend", {
  anchorID: "bend-anchor-id", // ID of the nonMergeable bend anchor
});

The anchor must be a bend anchor (nonMergeable: true). Both adjacent segments must belong to the same logical bundle. Any breaks on the merged segments are removed automatically.

Style Reference

Drawing and update commands use nested style objects for visual properties.

Shape Style (Line, Circle, Rectangle)

Used by: drawLine, drawCircle, drawRectangle, updateLine, updateCircle, updateRectangle

PropertyTypeDescription
strokeWidthnumberBorder/line thickness
strokeColorstring or [r,g,b]Border/line color
fillColorstring or [r,g,b]Fill color
dashArraynumber[]Dash pattern, e.g., [10, 5]

Text Style (TextContainer)

Used by: drawText, updateTextcontainer

PropertyTypeDescription
colorstring or [r,g,b]Text fill color
fontFamilystringFont name (e.g., "Arial")
fontWeightstring"normal", "bold", "lighter"
isItalicbooleanItalic text (default: false)
strokeColorstring or [r,g,b]Text outline color
strokeWidthnumberText outline thickness

Table Text Style (Pinout, CompWireTable)

Used by: updatePinout, updateCompwiretable

PropertyTypeDescription
fontSizenumberFont size
fontFamilystringFont name (e.g., "Arial")
fontWeightstring"normal", "bold"

Table textStyle Limitations

Table textStyle does NOT support isItalic or color - only fontSize, fontFamily, and fontWeight.

Color Formats

Colors can be specified as:

  • Hex strings: "#FF0000", "#f00", "red"
  • RGB arrays: [255, 0, 0] (values 0-255)

Query Commands

Find and retrieve element data. Queries use exact name matching (case-sensitive).

No Wildcards

Queries use exact matching only. You cannot use patterns like J* or PWR*. Instead, query all elements and filter with JavaScript.

queryComponent

javascript
// By exact name
const result = runScriptCommand("queryComponent", { query: "ECU1" });
if (result.success && result.elements.length > 0) {
  const comp = result.elements[0];
  scriptConsole.log(`Found: ${comp.name} with ${comp.pinCount} pins`);
}

// Get all components, then filter in JavaScript
const allComps = runScriptCommand("queryComponent", {});
const jConnectors = allComps.elements.filter(c => c.name.startsWith("J"));
scriptConsole.log(`Found ${jConnectors.length} J-series connectors`);

// By ID
const result = runScriptCommand("queryComponent", {
  query: { id: "comp-uuid-123" },
});

Returns: { success: boolean, elements: [...] } where elements have:

  • id, name, x, y, pinCount, partnumber, manufacturer, etc.

queryWire

javascript
// By exact name
const result = runScriptCommand("queryWire", { query: "PWR_MAIN" });

// Get all wires, then filter by property in JavaScript
const allWires = runScriptCommand("queryWire", {});
const redWires = allWires.elements.filter(
  w => w.colors && w.colors.includes("red")
);
scriptConsole.log(`Found ${redWires.length} red wires`);

Returns: Array of wire objects with:

  • id, name, colors, coreSizeAWG, fromComponent, fromPin, toComponent, toPin, etc.

queryBundle

javascript
const result = runScriptCommand("queryBundle", { query: "MAIN_TRUNK" });

queryPin

javascript
// Query pins on a component
const result = runScriptCommand("queryPin", { component: "ECU1" });

// Query specific pin
const result = runScriptCommand("queryPin", {
  component: "ECU1",
  pin: 3,
});

queryAnchor

Query anchors by ID only:

javascript
// Query specific anchor by ID
const result = runScriptCommand("queryAnchor", {
  query: { id: "anchor-uuid-string" },
});

// Get all anchors (no filter)
const allAnchors = runScriptCommand("queryAnchor", {});

ID-only queries

queryAnchor only supports querying by id. There is no bundle parameter. To find anchors on a specific bundle, query all anchors and filter in JavaScript.

querySideview

javascript
const result = runScriptCommand("querySideview", { component: "J101" });

queryPinout

javascript
const result = runScriptCommand("queryPinout", { component: "ECU1" });

Update Commands

Modify existing elements. Requires exact name or ID in the query parameter.

Update Syntax

Update commands use { query: '...', update: {...} } format. You must specify the exact element to update—wildcards are not supported.

updateComponent

javascript
runScriptCommand("updateComponent", {
  query: "ECU1", // Target by exact name
  update: {
    partnumber: "NEW-PART", // Properties to update
    manufacturer: "Bosch",
  },
});

// Update by ID
runScriptCommand("updateComponent", {
  query: { id: "comp-uuid-123" },
  update: { name: "ECU_RENAMED" },
});

updateWire

javascript
runScriptCommand("updateWire", {
  query: "PWR_MAIN", // Exact wire name
  update: {
    colors: ["red"],
    coreSizeAWG: "14",
  },
});

// To update multiple wires, query all then iterate
const allWires = runScriptCommand("queryWire", {});
allWires.elements.forEach(wire => {
  if (wire.name.startsWith("SIG")) {
    // JavaScript filtering
    runScriptCommand("updateWire", {
      query: wire.name,
      update: { coreSizeAWG: "22" },
    });
  }
});

updateBundle

javascript
runScriptCommand("updateBundle", {
  query: "MAIN_TRUNK",
  update: {
    tubingType: "conduit",
    coveringColor: "grey",
  },
});

updateAnchor

javascript
runScriptCommand("updateAnchor", {
  query: { id: "anchor-uuid" },
  update: {
    x: 350,
    y: 200,
  },
});

updatePin

javascript
runScriptCommand("updatePin", {
  component: "ECU1",
  pin: 1,
  update: {
    name: "VBAT",
    function: "power",
  },
});

updateLine

Updates a line's geometry and style.

javascript
runScriptCommand("updateLine", {
  query: "BORDER_LINE",
  update: {
    coords: { x: 0, y: 0 },
    coordsEnd: { x: 100, y: 100 },
    style: {
      strokeWidth: 2,
      strokeColor: "#FF0000",
      dashArray: [10, 5],
    },
  },
});

updateCircle

Updates a circle's geometry and style.

javascript
runScriptCommand("updateCircle", {
  query: "MARKER_CIRCLE",
  update: {
    coords: { x: 250, y: 250 },
    radius: 75,
    style: {
      strokeWidth: 2,
      strokeColor: "#0000FF",
      fillColor: "#CCCCFF",
    },
  },
});

updateRectangle

Updates a rectangle's geometry and style.

javascript
runScriptCommand("updateRectangle", {
  query: "FRAME_RECT",
  update: {
    width: 200,
    length: 100,
    style: {
      strokeWidth: 1,
      strokeColor: "#000000",
      fillColor: "#FFFFCC",
    },
  },
});

updateTextcontainer

Updates a text element. Note: Uses style (not textStyle).

javascript
runScriptCommand("updateTextcontainer", {
  query: "TITLE_TEXT",
  update: {
    text: "Updated Label",
    fontSize: 16,
    style: {
      color: "#333333",
      fontFamily: "Arial",
      fontWeight: "bold",
      isItalic: true,
    },
  },
});

updatePinout

Updates a component's pinout table appearance.

javascript
runScriptCommand("updatePinout", {
  query: "J101", // Parent component name
  update: {
    colSizes: { x: 60, y: 25 },
    numColsRows: { x: 4, y: 2 },
    textStyle: {
      fontSize: 10,
      fontFamily: "Courier",
      fontWeight: "normal",
    },
  },
});

updateCompwiretable

Updates a component's wire table appearance.

javascript
runScriptCommand("updateCompwiretable", {
  query: "J101", // Parent component name
  update: {
    colSizes: { x: 80, y: 20 },
    isFlip: false,
    textStyle: {
      fontSize: 12,
      fontFamily: "Arial",
      fontWeight: "bold",
    },
  },
});

Move Commands

Reposition elements.

move

javascript
// Single element - absolute position
runScriptCommand("move", {
  queries: [{ type: "component", query: "J101" }],
  position: { x: 500, y: 300 },
});

// Single element - relative movement
runScriptCommand("move", {
  queries: [{ type: "component", query: "J101" }],
  position: { dx: 100, dy: -50 }, // Move 100 right, 50 up
});

// Multiple elements - MUST use relative position
runScriptCommand("move", {
  queries: [
    { type: "component", query: "J101" },
    { type: "component", query: "J102" },
    { type: "wire", query: "PWR_MAIN" },
  ],
  position: { dx: 100, dy: 0 }, // Relative required for multiple
});

Query types: component, wire, bundle, anchor, sideview, pinout

Multiple elements

When moving multiple elements, you MUST use relative position (dx, dy). Absolute position (x, y) only works for a single element.


Erase Commands

Delete elements.

eraseComponent

javascript
runScriptCommand("eraseComponent", { query: "J101" });

// By ID
runScriptCommand("eraseComponent", { query: { id: "comp-uuid" } });

eraseWire

javascript
runScriptCommand("eraseWire", { query: "PWR_MAIN" });

eraseBundle

javascript
runScriptCommand("eraseBundle", { query: "MAIN_TRUNK" });

eraseDimension, eraseTextcontainer, eraseImage, eraseSvg

javascript
runScriptCommand("eraseDimension", { query: { id: "dim-uuid" } });
runScriptCommand("eraseTextcontainer", { query: { id: "text-uuid" } });
runScriptCommand("eraseImage", { query: { id: "img-uuid" } });
runScriptCommand("eraseSvg", { query: { id: "svg-uuid" } });

Utility Commands

copyWire

Duplicates wire configuration from one pin to another.

javascript
runScriptCommand("copyWire", {
  from: { componentName: "ECU1", pinName: "1" },
  to: { componentName: "ECU1", pinName: "2" },
});

mergeAnchors

Combines multiple anchor points into one.

javascript
runScriptCommand("mergeAnchors", {
  anchors: ["anchor-1", "anchor-2", "anchor-3"],
  target: { x: 300, y: 200 }, // Position for merged anchor
});

makeSideview

Links an image or SVG to a component as its sideview (connector shell representation).

javascript
runScriptCommand("makeSideview", {
  image: { type: "image", query: { id: "image-id" } },
  component: { query: "J101" },
});

convertToSideview

Converts an SVG or image into a sideview.

javascript
runScriptCommand("convertToSideview", {
  type: "svg", // or "image"
  query: { id: "svg-element-id" },
});

rehangWire

Reconnects a wire to a different pin.

javascript
runScriptCommand("rehangWire", {
  wire: "PWR_MAIN",
  endpoint: "from", // 'from' or 'to'
  newPin: { componentName: "ECU2", pinName: "1" },
});

Script Output

Use scriptConsole (not console) for output:

javascript
scriptConsole.log("Information message");
scriptConsole.warning("Warning message");
scriptConsole.critical("Error message");
scriptConsole.table(data); // Display tabular data

Enums Reference

Wire Colors (DIN 47100)

Single colors: white, brown, green, yellow, grey, pink, blue, red, black, violet, orange

Two-color combinations (stripe): Use array format: ['white', 'green'], ['red', 'blue'], ['yellow', 'brown'], etc.

Tubing Types

heatshrink, coldshrink, sleeving, braidedsleeving, solid, wireloom, conduit, pvccoated

Wire Types

singlecore, multicore, twisted

Pin Numbering Order

column, row

Gender

male, female

Join Type

crimp, solder


Next Steps