How to copy, mirror and rotate a cell?

I am new to python script and klayout.

I have a gds file named "8th.gds", which contains 8th of the whole layout.
Now I want to copy it eight times, rotating and mirroring the duplication at the same time.

How to realize it with python script? Like "pya.CellInstArray(cell_index,pya.Trans(pya.Point(0,0)))" ?
Thanks a lot.


  • edited December 2021


    here is some sample code which places a cell called "F" 8 times. It creates a new top cell called "TOP" for this purpose:

    import pya
    ly =
    # TODO: change name
    cell_to_place = ly.cell("F")
    # TODO: change name
    new_top_cell = ly.create_cell("TOP")
    # displacement in database units between each instances
    d = 2500
    x = 0
    for t in [ pya.Trans.R0, pya.Trans.R90, pya.Trans.R180, pya.Trans.R270, 
               pya.Trans.M0, pya.Trans.M45, pya.Trans.M90,  pya.Trans.M135 ]:
      new_top_cell.insert(pya.CellInstArray(cell_to_place.cell_index(), pya.Trans(x, 0) * t))
      x += d

    It produces this layout from a single "inverse F" cell with with 2x2µm dimension (1nm DBU):


Sign In or Register to comment.