# GDSII and OASIS command-line tools
Install the CLI with `cargo install layouttk --locked`. Run `layouttk --help` for the commands and `layouttk create --help` for command-specific options. Use the [Python API](https://docs.rs/layouttk/0.2.0/layouttk/guides/python_api/) for scripted geometry, analysis, and array exchange.
## Create a hierarchical layout
Save the following as `mask.json`. The parent places `PAD` on a one-nanometre grid. Coordinates are integer DBU and layers are `[layer, datatype]`.
```json
{
"version": 1,
"name": "MASK",
"dbu_nm": 1,
"cells": [
{"name": "TOP", "elements": [
{"kind": "reference", "target": "PAD", "origin": [300, -100]}
]},
{"name": "PAD", "elements": [
{"kind": "rectangle", "layer": [67, 20], "corner1": [0, 0], "corner2": [100, 40]}
]}
]
}
```
```sh
layouttk create mask.json mask.oas
layouttk create - mask.gds < mask.json
layouttk inspect mask.oas
```
`create` accepts a JSON file or standard input (`-`). The output extension selects GDSII or OASIS. A cell may refer to another definition later in the same request. Omitting the cell's `elements` creates an empty definition. GDSII stores `name` as the library name. OASIS reads back with the name `LIBRARY`.
Provide one positive grid spacing. Use `dbu_nm` for nanometres per DBU. Version-1 input with `dbu_meters` remains accepted.
| `kind` | Required fields | Optional fields |
| --- | --- | --- |
| `rectangle` | `layer`, `corner1`, `corner2` | |
| `polygon` | `layer`, `points` with an implicit closing edge | |
| `path` | `layer`, `points`, nonnegative `width` in DBU | |
| `circle` | `layer`, `center`, `radius` in DBU, for OASIS output | |
| `text` | `layer` with texttype as its second item, `origin`, `text` | |
| `reference` | `target`, `origin` | `angle_deg` (default `0`), `reflect_x` (default `false`), `magnification` (default `1`), `array` |
An `array` contains `columns`, `rows`, `column_step`, and `row_step`. Steps are vectors in the containing cell's coordinates. A path has flush ends. Use Python for custom caps, text styles, typed properties, and other repetition types.
## Inspect, extract, and convert
```sh
layouttk inspect mask.oas
layouttk extract mask.oas metal.gds --top TOP --layer 67/20
layouttk check metal.gds --to oas --json
layouttk convert metal.gds metal.oas
```
- `inspect` prints JSON with `dbu_meters`, `top_cells`, `layers`, and stored counts. A compact array counts as one stored record.
- `extract` applies layer selection while decoding, then keeps the selected root and its dependencies. Repeat `--layer` to retain several layer/type pairs.
- `check --json` reports `can_write` and field-level diagnostics. A failed check exits nonzero. Parse JSON from stdout and read stderr for the process error.
- `create`, `extract`, and `convert` use the target encoder before replacing the destination. To encode a flush path with an odd total width in OASIS, use `--regrid-factor 2` to keep the physical size while doubling integer coordinates.
Use `--oas-budget-bytes` to set the OASIS retained-data budget for input. See the [KLayout read-back example](https://docs.rs/layouttk/0.2.0/layouttk/guides/interoperability/) for an independent geometry check. Query windows, compare geometry by XOR, and make pixel masks with the [Python workflows](https://docs.rs/layouttk/0.2.0/layouttk/guides/python_workflows/) and [binary image tutorial](https://docs.rs/layouttk/0.2.0/layouttk/guides/raster_images/).
## Inventory and verify a handoff
```sh
layouttk inventory mask.oas --top TOP --layer 67/20
layouttk verify mask.gds mask.oas --left-top TOP --right-top TOP --layer 67/20
```
`inventory` retains the reference graph and counts shapes and text while decoding. Omitting `--top` reports all definitions and unresolved names. Selecting a root reports its dependency closure. Layer summaries distinguish geometry from text, and occurrence counts account for repetitions local to each definition. They do not count globally expanded descendants.
`verify` compares the selected dependency trees on compatible physical grids. It compares stored records by cell name and category in their stored order, and separately reports placed mask XOR by layer. Different cell names or record representations can yield different stored results with equal placed material. Grid incompatibility requires explicit resampling before verification. Paths and circles are outlined at `--tolerance-dbu`, and `--limit` bounds each expansion when the placed geometry must be evaluated.
Both commands report `schema_version`, `status`, and `report` in JSON. Verification exits successfully on `equal` and exits nonzero on `different` or an operational `error`. Argument validation errors are reported by the CLI parser.
## Clip windows from a large file
```sh
layouttk clip mask.oas clips.oas --top TOP --layer 67/20 \
--window=300,-100,350,-60 --window=650,0,700,200
```
Corners are ordered `x0,y0,x1,y1` in root DBU. A seekable source is scanned twice. The first pass retains the graph and the second keeps clipped output. Output is one atomically replaced file with independent, flat polygon cells `WIN_1`, `WIN_2`, and so on. Original coordinates are preserved. Empty and repeated windows retain their positions in the JSON report. Polygon output represents filled material. Paths and circles are outlined, arrays are expanded up to `--placement-limit`, and labels and source properties are omitted.
Use `--output-vertex-limit` to limit the total stored output across windows. The source still needs space for graph, name tables and decoder buffers. Very large compact arrays may exceed the placement limit, even for a small window. Use the in-memory `analysis.clip_windows` for already loaded layouts and `extract` for hierarchy-preserving layer selection.