Your First Script
This tutorial walks through running your first Python script in LinkCAD’s interactive console.
Open the Console
Go to View → Python Console (Ctrl+Shift+P). A Python prompt appears at the bottom of the window.
Hello World
Type the following and press ↵:
print("Hello from LinkCAD!")You should see the output in the console.
Exploring the Drawing
With a file loaded, you can inspect its structure:
from linkcad.v1.db import Drawing
# Get the current drawingdwg = Drawing.current()
# List all cellsfor cell in dwg.cells(): print(f"Cell: {cell.name}")
# List all layersfor layer in dwg.layers(): print(f"Layer: {layer.name}")Counting Shapes
from linkcad.v1.db import Drawing
dwg = Drawing.current()main = dwg.main_cell()
count = 0for shape in main.shapes(): count += 1print(f"Total shapes in main cell: {count}")Using the Script Editor
For longer scripts, use the built-in editor:
- Open View → Python Script Editor (Ctrl+Shift+E)
- Write your script in the editor
- Press F5 to run the entire script
- Or select lines and press Ctrl+↵ to run just the selection
Next Steps
- Writing a Tool Plugin — create a reusable tool with a GUI dialog
- Writing a Format Plugin — add a custom file format