linkcad.plugin
The plugin module provides the framework for creating tools, format readers, and format writers.
Decorators
@tool()
Registers a class as a menu tool. See Tool Decorator.
@format_reader()
Registers a class as a file import format. See Format Decorators.
@format_reader(name="My Format", extensions=["*.myf"])
class MyReader(FormatReader):
def read(self, path: Path, drawing: DrawingContext) -> None:
...
@format_writer()
Registers a class as a file export format. See Format Decorators.
@format_writer(name="My Format", extensions=["*.myf"])
class MyWriter(FormatWriter):
def write(self, path: Path, drawing: WriterContext) -> None:
...
Option Class
Option provides factory methods for defining typed, persistent options:
| Factory | Result Type | UI Control |
|---|---|---|
Option.integer(label, default, min, max) |
int |
Spin box |
Option.real(label, default, min, max, decimals) |
float |
Double spin box |
Option.boolean(label, default) |
bool |
Checkbox |
Option.string(label, default) |
str |
Text field |
Option.choice(label, choices, default) |
str |
Dropdown |
Option.path(label, default, file_filter) |
str |
File picker |
Option.color(label, default) |
str |
Color picker |
Option.table(label, columns, default) |
list[dict] |
Editable grid |
Option.cell_choice(label, default) |
str |
Cell dropdown |
All factories accept optional tooltip and enabled_when parameters.
Context Classes
DrawingContext
Builder interface for format readers. Methods:
cell(name, main)— context manager for creating cellsiter_lines(path)— line iterator with progressiter_binary(path, chunk_size)— binary iterator with progressprogress— get/set progress (0.0–1.0)
WriterContext
Reader interface for format writers. Methods:
shapes(cell, layer)— iterate shapes with progressshapes_by_layer(cell)— shapes grouped by layershapes_by_cell(layer)— shapes grouped by cellcells()— cell name iteratorlayers()— layer name iteratorcell_count()/shape_count()— countsmain_cell_name()— top cell nameflatten— get/set hierarchy flattening
ShapeInfo
Data class yielded by WriterContext.shapes():
layer_name: str— layer namecell_name: str— cell namevertices: list[tuple]— (x, y) coordinatesis_polygon: bool— polygon vs. polylinewidth: int— polyline widthis_closed: bool— whether the shape is closed
Exceptions
| Exception | Use |
|---|---|
PluginError |
Base class for all plugin errors |
ParseError |
File parsing errors (accepts line and path kwargs) |
WriteError |
File writing errors |
ValidationError |
Option validation errors |
TableColumn
Data class for defining table option columns:
key: str— dict keylabel: str— column headercol_type: str—string,integer,real,choice,cell_choicedefault: Any— default valuechoices: list[str]— forchoicecolumnsdecimals: int— forrealcolumnsmin_value/max_value— for numeric columns