Command Reference
This page documents all script commands available in LoomCAD.
Command Syntax
All commands follow this pattern:
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).
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):
// 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.
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.
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.
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):
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.
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,sleevingbraidedsleeving,solid,wireloomconduit,pvccoated
drawLine
Creates a decorative line (not electrical).
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.
runScriptCommand("drawCircle", {
center: { x: 200, y: 200 },
radius: 50,
style: {
strokeWidth: 1,
strokeColor: "#000000",
fillColor: "#ffffff",
},
});drawRectangle
Creates a rectangle shape.
runScriptCommand("drawRectangle", {
start: { x: 100, y: 100 },
end: { x: 300, y: 250 },
style: {
strokeWidth: 1,
strokeColor: "#000000",
fillColor: "#f0f0f0",
},
});drawText
Creates a text annotation.
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.
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.
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.
runScriptCommand("drawSVG", {
svg: "<svg>...</svg>", // SVG content
x: 100,
y: 100,
});drawBundleBreak
Adds a break point to a bundle.
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.
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.
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
| Property | Type | Description |
|---|---|---|
strokeWidth | number | Border/line thickness |
strokeColor | string or [r,g,b] | Border/line color |
fillColor | string or [r,g,b] | Fill color |
dashArray | number[] | Dash pattern, e.g., [10, 5] |
Text Style (TextContainer)
Used by: drawText, updateTextcontainer
| Property | Type | Description |
|---|---|---|
color | string or [r,g,b] | Text fill color |
fontFamily | string | Font name (e.g., "Arial") |
fontWeight | string | "normal", "bold", "lighter" |
isItalic | boolean | Italic text (default: false) |
strokeColor | string or [r,g,b] | Text outline color |
strokeWidth | number | Text outline thickness |
Table Text Style (Pinout, CompWireTable)
Used by: updatePinout, updateCompwiretable
| Property | Type | Description |
|---|---|---|
fontSize | number | Font size |
fontFamily | string | Font name (e.g., "Arial") |
fontWeight | string | "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
// 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
// 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
const result = runScriptCommand("queryBundle", { query: "MAIN_TRUNK" });queryPin
// 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:
// 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
const result = runScriptCommand("querySideview", { component: "J101" });queryPinout
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
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
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
runScriptCommand("updateBundle", {
query: "MAIN_TRUNK",
update: {
tubingType: "conduit",
coveringColor: "grey",
},
});updateAnchor
runScriptCommand("updateAnchor", {
query: { id: "anchor-uuid" },
update: {
x: 350,
y: 200,
},
});updatePin
runScriptCommand("updatePin", {
component: "ECU1",
pin: 1,
update: {
name: "VBAT",
function: "power",
},
});updateLine
Updates a line's geometry and style.
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.
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.
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).
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.
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.
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
// 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
runScriptCommand("eraseComponent", { query: "J101" });
// By ID
runScriptCommand("eraseComponent", { query: { id: "comp-uuid" } });eraseWire
runScriptCommand("eraseWire", { query: "PWR_MAIN" });eraseBundle
runScriptCommand("eraseBundle", { query: "MAIN_TRUNK" });eraseDimension, eraseTextcontainer, eraseImage, eraseSvg
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.
runScriptCommand("copyWire", {
from: { componentName: "ECU1", pinName: "1" },
to: { componentName: "ECU1", pinName: "2" },
});mergeAnchors
Combines multiple anchor points into one.
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).
runScriptCommand("makeSideview", {
image: { type: "image", query: { id: "image-id" } },
component: { query: "J101" },
});convertToSideview
Converts an SVG or image into a sideview.
runScriptCommand("convertToSideview", {
type: "svg", // or "image"
query: { id: "svg-element-id" },
});rehangWire
Reconnects a wire to a different pin.
runScriptCommand("rehangWire", {
wire: "PWR_MAIN",
endpoint: "from", // 'from' or 'to'
newPin: { componentName: "ECU2", pinName: "1" },
});Script Output
Use scriptConsole (not console) for output:
scriptConsole.log("Information message");
scriptConsole.warning("Warning message");
scriptConsole.critical("Error message");
scriptConsole.table(data); // Display tabular dataEnums 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
- Scripting Basics - Get started with scripts
- Script Libraries - Save and reuse scripts
- Debugging Scripts - Troubleshoot errors