Select a cell and change layer


I am very new to Klayout scripting and would like to write my first script (ruby and/or python) which does the following:

Select a cell in a layout using cell name (e.g. “example_cell”) and change gds layer from original layer to a new layer (e.g. change from layer 112/2 to layer 101/1).

I have written the following code to generate the new gds layer (don’t know if it is the best way to do it but it works), now I’m missing the part to select cell “example_cell” and change gds layer.

app = RBA::Application.instance

mw = app.main_window

layout_view = mw.current_view

layer_info =,1)
layer_pn = RBA::LayerPropertiesNode::new

layer_pn.source = layer_info.to_s
layout_view.insert_layer( layout_view.end_layers, layer_pn )

Thanks for support.


  • edited May 2019


    Here is some sample script (Python). With other values, but the comments should make it easy to adjust the script:

    # fetches current layout view and cell view
    view = pya.LayoutView.current()
    cellview =
    # gets the corresponding layout object
    layout = cellview.layout()
    # gets the cell to change is "INV2X"
    cell_to_change = layout.cell("INV2X")
    # finds source layer: GDS layer 1, datatype 0
    source_layer = layout.layer(1, 0)
    # finds (or creates) target layer: GDS layer 10, datatype 0
    target_layer = layout.layer(10, 0)
    # gets the Shapes object which holds the shapes of a cell/layer
    # for source:
    source_shapes = cell_to_change.shapes(source_layer)
    # for target:
    target_shapes = cell_to_change.shapes(target_layer)
    # moves shapes
    # makes sure the new layer is shown


  • Hello Matthias, thanks for your feedback!

Sign In or Register to comment.