Skip to content

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 Enter:

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 import db

# Get the current drawing
dwg = db.Drawing.current()

# List all cells
for cell in dwg.cells():
    print(f"Cell: {cell.name}")

# List all layers
for layer in dwg.layers():
    print(f"Layer: {layer.name}")

Counting Shapes

from linkcad import db

dwg = db.Drawing.current()
main = dwg.main_cell()

count = 0
for shape in main.shapes():
    count += 1
print(f"Total shapes in main cell: {count}")

Using the Script Editor

For longer scripts, use the built-in editor:

  1. Open View → Python Script Editor (Ctrl+Shift+E)
  2. Write your script in the editor
  3. Press F5 to run the entire script
  4. Or select lines and press Ctrl+Enter to run just the selection

Next Steps