Copy a layer to another layer

Hi, I am new in Klayout world. Trying to achieve something wiht a layout having cells and subcells in the heirarchy. I want to copy a layer (layer1) and put that into a new layer (layer2). I tried the following code. This runs and shows no error but not copying anything..

import pya
layout = pya.Application.instance().main_window().current_view().active_cellview().layout() 

src_lay=1
des_lay=2

for c in layout.each_cell():
    print(c.name)
    topcell=layout.cell(c.name)
    topcell.copy(src_lay,des_lay)

Comments

  • edited April 14

    I tried this and now it wokrs.. i wonder what is the difference -

    import pya
    layout = pya.Application.instance().main_window().current_view().active_cellview().layout() 
    
    src_layer=1
    des_layer=2
    
    for c in layout.each_cell():
        print(c.name)
        src_layer1 = pya.LayerInfo.new(src_layer,0)
        src_lay=layout.layer(src_layer1)
        des_layer1 = pya.LayerInfo.new(des_layer,0)
        des_lay=layout.layer(des_layer1)
        topcell=layout.cell(c.name)
        topcell.copy(src_lay,des_lay)
    
  • edited April 19

    @sheikh_nir The layer numbers you need for "copy" are "layer indexes", not particular design layers. A layer index is an internal number of the layer. A design layer is given by a combination of layer number and datatype number or a name summarized in the "LayerInfo" structure. "layout.layer(LayerInfo)" will give you the index under which a design layer specified by the LayerInfo structure is stored or it will generate a new layer if no such layer exists.

    Within this concept you can also generate anonymous layers not begin associated with a design layer.

    Matthias

  • Thanks @Matthias for the explanation. This makes all the sense :)

Sign In or Register to comment.