Python Scripting
LinkCAD includes an embedded Python interpreter for custom automation, tool development, and format plugin creation. Python scripts can access the full drawing database and geometry API.
Features
- Custom Tools — create menu items that process drawing geometry
- Format Plugins — add support for new import/export file formats
- Interactive Console — explore and manipulate drawings live
- Script Editor — write and run scripts from within LinkCAD
Getting Started
- Setup & Requirements — Python environment and prerequisites
- Your First Script — "Hello World" in the Python console
- Writing a Tool Plugin — create a menu-integrated tool
- Writing a Format Plugin — add a new file format
- Panel Assembly Tutorial — complete real-world example
API Reference
- Option Types — integer, real, boolean, string, choice, path, color, table, cell_choice
- Tool Decorator —
@tool()decorator and Tool base class - Format Decorators —
@format_reader(),@format_writer(), and base classes - API Modules —
linkcad.plugin,linkcad.db,linkcad.geom
Quick Example
A simple tool that counts shapes per layer:
from linkcad.plugin import tool, Tool
@tool(
name="Layer Statistics",
menu="Tools/Analysis",
tooltip="Count shapes per layer",
)
class LayerStats(Tool):
def run(self, drawing) -> None:
for layer_name, shapes in drawing.shapes_by_layer():
count = sum(1 for _ in shapes)
print(f"{layer_name}: {count} shapes")