Clip
This example clips a rectangular region taken from layer 100/0 and saves this clip as a new layout. The clip is generated in-place which means that no new cells need to be generated if cells are entirely inside the clip box.
This example demonstrates:
- How to use
clip
from the Layout object (see original documentation ofclip
). - Saving cells to layout files using
write
of the Cell object.
Note that the clip is done hierarchically - i.e. preserving the original hierarchy where possible. With this particular example (a layer from a SRAM) this is much more efficient than a flat clip using a boolean operation.
Note: This sample can easily be extended to provide a clip at multiple boxes at once.
Use multi_clip
instead of clip
and collect the clip boxes from layer 100/0 instead of taking the
bounding box.
Code:
import klayout.db as db
import math
ly = db.Layout()
ly.read("input.gds")
clip_layer = ly.layer(100, 0)
# Note that we use "bbox" to get the integer-unit bounding box
clip_box = ly.top_cell().bbox_per_layer(clip_layer)
# The clip method only takes integer-unit clip boxes so far.
# It takes and returns cell indexes.
clip_cell_index = ly.clip(ly.top_cell().cell_index(), clip_box)
clip_cell = ly.cell(clip_cell_index)
clip_cell.name = "CLIP"
clip_cell.write("clip.gds")
Input input.gds
(the white box is on layer 100/0):
Result (a cutout from the original layout):