Simple multi_clip_into(...) script

edited September 2020 in Python scripting

Hey folks,

I am trying to make a simple "multi clip" script that takes a list of boxes and clips a layout file similar to how this tool works:

edit->utilities->Clip Tool->multi clip

I found a few discussions that are close to showing how to do this:

I think it would be something very simple like this, but the output.oas file is empty

import pya

layout_file = "C:/~/input.oas"
layout =

top_cell = layout.cell('my_top_cell_name')

bblist = [
  # Left, Right, Bottom, Top, 1000, 0, 1000),, 2000, 1001, 2000)

clip_layout =


for layer_id in layout.layer_indexes():
  clip_layout.insert_layer_at(layer_id, layout.get_info(layer_id))

clip_cells = layout.multi_clip_into(top_cell.cell_index(), clip_layout, bblist)




  • Hi Scott,

    you gave me some headache before I found the problem :)

    Here is the explanation: the box coordinates are actually left, bottom, right, top. So the list should be:

    bblist = [
      # Left, Bottom, Right, Top, 0, 1000, 1000),, 1001, 2000, 2000)

    With your definition you clipped only single points. A clip at a single point gives as much as fits into a point which is nothing :)


  • edited September 2020

    Thank you Matthias. Small problem... each bbox clip goes into a separate cell. Any way to make all clips go into one cell? Like how the multi clip utility arranges all the cells under a new top cell named CLIP


  • Also thank you a bunch for looking into this... that's quite a dumb mistake putting the bbox corners in the wrong order :(

  • Hi Scott,

    that's easy. Just instantiate the new cells into a new top cell:

    # needs to go before the "write"
    clip_top = clip_layout.create_cell("CLIP")
    for cc in clip_cells:
      clip_top.insert(pya.CellInstArray(cc, pya.Trans()))



  • Thanks Matthias! I am slowly getting more comfortable with the Klayout scripting API. This is going to save a lot of time and effort for a bunch of poor lithography engineers :)

Sign In or Register to comment.