linkcad.db
The database module provides access to LinkCAD's in-memory drawing database. All database objects are backed by C++ implementations for performance.
Classes
Drawing
The top-level container for all layout data.
| Method | Description |
|---|---|
Drawing.current() |
Get the active drawing instance |
dwg.main_cell() |
Get the main (top) cell |
dwg.cells() |
Iterate all cells |
dwg.layers() |
Iterate all layers |
dwg.find_cell(name) |
Find a cell by name |
dwg.find_layer(name) |
Find a layer by name |
Cell
A named container of shapes and cell references.
| Property / Method | Description |
|---|---|
cell.name |
Cell name |
cell.shapes() |
Iterate shapes in this cell |
cell.refs() |
Iterate cell references |
cell.add_ref(cell, position) |
Add a cell reference |
Cell.create(drawing, name) |
Create a new cell |
Layer
A named layer with display properties.
| Property / Method | Description |
|---|---|
layer.name |
Layer name |
layer.number |
Layer number (for GDSII) |
layer.datatype |
Layer datatype (for GDSII) |
layer.visible |
Whether the layer is visible |
layer.color |
Layer display color |
Shape
Base class for all geometric shapes (polygons, polylines, circles, text).
| Property / Method | Description |
|---|---|
shape.layer() |
Get the shape's layer |
shape.vertices() |
Get vertex coordinates |
shape.closed |
Whether the shape is closed |
shape.bounds() |
Get the bounding box |
Ref
A reference to another cell, with transformation.
| Property / Method | Description |
|---|---|
ref.cell |
Referenced cell |
ref.position |
Reference position |
ref.transformation |
Applied transformation |
Locking
All database access requires proper locking:
ReadLock
from linkcad.db import ReadLock
with ReadLock():
cell = dwg.main_cell()
for shape in cell.shapes():
print(shape.vertices())
Transaction
Write operations require a Transaction. The transaction auto-commits when the with block exits without an exception, and auto-rolls-back if an exception occurs.
from linkcad.db import Transaction
with Transaction(dwg) as txn:
cell = Cell.create(dwg, "new_cell")
# ... modify drawing ...
# auto-commits on successful exit
Warning
Accessing the database without a lock causes undefined behavior. Always use ReadLock for reads and Transaction for writes.