Merging multiple GDS containing the same cell name

edited November 2023 in Python scripting


I would like to merge multiple GDS that contain the same cell name by running .tpl file using Python.
But once I merged, the cell will have the same layer overlapped with number of the cells.
Can I avoid this? Even if you have the same cell name, merge them with only one cell not ovelapping.

I use this code for merging cells.

for cell in final_layout.top_cells():
    if != "{{top_level[0]}}":
        new_instance = pya.CellInstArray(cell.cell_index(), pya.Trans(x, y) * rotation)


  • Could you give some context ?
    Any specific reason why you want to do that inside klayout using a script ?
    This can also be done with klayout's buddy tools strm2gds/strm2oas, which will take care of uniquification.

    strm2oas a.gds,b.gds.gz,c.oas collected.oas

    I can't answer your original questions, but I'm pretty sure it can be done with python scripting too.

  • I believe that File>Import>Other_Files_Into_Current from
    another GDS file" will "uniquify" duplicate names encountered
    during the import, if you use the menu command.

  • Thank you guys,
    I think Stefan's suggestion make sense, maybe I can use some python package for this function

  • In Python, the solution is simply

    ly = pya.Layout()"file1.gds")"file2.gds")

    Cells with the same name in "file1.gds" and "file2.gds" will be merged into one cell. If that happens for the top level cell, this is usually fine and to my understanding this is what you need. If it happens for child cells however, the result is usually not useful. I would recommend this way only for flat layouts or when it is made sure by other ways that child cells carry different names in the different files.


  • Thank @Matthias
    It is apparently for the case the sub childs, so your recommendation was not the perfect solution.
    Do we have any other solution?

  • The more elaborate solution is to load into two separate layouts and merge:

    ly1 = pya.Layout()"file1.gds")
    ly2 = pya.Layout()"file2.gds")
    # merge ly2's top cell into ly1's top cell
    # NOTE: "move_tree" will empty ly2, but is more memory efficient


Sign In or Register to comment.