From klayoutclaw
Imports a GDS file into KLayout, flattening hierarchy and merging into a single top cell to avoid Layout.read() pitfalls like orphaned cell indices and multi-top-cell states.
How this skill is triggered — by the user, by Claude, or both
Slash command
/klayoutclaw:klayout_gds_importThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Import a GDS file into the running KLayout session in a way that avoids the
Import a GDS file into the running KLayout session in a way that avoids the
well-known Layout.read() pitfalls documented in CLAUDE.md:
cells() reports N but cell(N-1) is
invalid).CellView.cell may point at a destroyed cell,
causing downstream crashes.This skill provides a single-shot importer that:
CellView.cell to the resolved top, zooms to fit, and refreshes
the layer panel.| Parameter | Type | Default | Description |
|---|---|---|---|
filepath | string | — | Required. Absolute path to a .gds file on disk. |
flatten | bool | true | If true, flatten all subcells into the top cell after reading (cell.flatten(-1, True)). |
merge_into_current | bool | true | If true, merge the GDS shapes into the currently focused layout. If false, open a new tab via mw.create_layout(1) first. |
From a shell with access to the KlayoutClaw MCP server:
python skills/klayout_gds_import/scripts/import_gds.py \
--filepath /path/to/template.gds \
--flatten \
--merge-into-current
To import into a fresh tab (non-destructive to existing work):
python skills/klayout_gds_import/scripts/import_gds.py \
--filepath /path/to/template.gds \
--no-merge-into-current
On success the script prints a JSON blob like:
{"status": "ok", "top_cell": "TOP", "shapes_added": 1342}
On failure:
{"status": "error", "error": "<message + traceback>"}
each_top_cell() (never cell(i) by index) to avoid the
orphaned-slot crash documented in CLAUDE.md.flatten=true leaves more than one
top cell, the importer picks the top cell with the largest bbox as the
canonical top, moves shapes from the other top cells into it shape-by-shape
via shapes().each() + shapes().insert(), and deletes the emptied cells.CellView.cell — after the read, the importer explicitly
rebinds cv.cell = <resolved_top> before returning, matching the pattern in
CLAUDE.md under "Dangling cv.cell after Layout.read()".Layout.clear() when
merge_into_current=true, so existing user geometry is preserved.LayoutView, not the
Layout, so a plain read() does not touch them.scripts/import_gds.pyskills/scripts/mcp_client.py (shared MCP client)CLAUDE.md sections on Layout.read() cell-name
collisions and dangling cv.cell.npx claudepluginhub caidish/klayoutclaw --plugin klayoutclawCreates geometry in KLayout — rectangles, polygons, paths, cells, and cell instances via MCP scripts. Use for layout/chip/mask design tasks triggered by phrases like 'draw a rectangle' or 'add a polygon'.
Drives an open-source EDA flow from RTL to GDS with signoff checks (DRC, LVS, RCX) using OpenROAD-flow-scripts, Yosys, KLayout, and OpenRCX. Use for synthesis, place-and-route, GDS output, signoff verification, or PPA iteration.
Fixes SVG files for KiCad PCB import by splitting compound paths with holes, correcting Illustrator DPI scale (72 to 96), and converting CSS styles to inline attributes.