Python Scripting
LinkCAD includes an embedded Python interpreter for custom automation, tool development, and format plugin creation. Python scripts can access the drawing database, geometry API, and the linkcad.v1 plugin framework.
Features
- Custom Tools — create menu items that process drawing geometry
- Format Plugins — add import/export formats with
FormatReader,FormatWriter,DrawingBuilder, andWriterController - Interactive Console — explore and manipulate drawings live
- Script Editor — write and run scripts from within LinkCAD
The Python API remains in the stable linkcad.v1 namespace. Current format-plugin and database additions are part of v1; there is no v2 migration path to apply.
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 — all modules:
linkcad.v1.plugin,linkcad.v1.db,linkcad.v1.geom,linkcad.v1.edit,linkcad.v1.env,linkcad.v1.conv,linkcad.v1.libgraph,linkcad.v1.controller
Quick Example
A simple tool that counts shapes per layer:
from linkcad.v1.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")