A multi-layer layout Example Scripted by Python


I have recently started using python scripting in Klayout environment to create a set of layouts. My main idea of scripting the layout is to parametrize the variables in my layout.

I wonder if you have any examples of a simple multi-layer layout that I can follow and learn what I need to do to create my layout. I have gone through some of the examples available in the example package. Although they helped me familiarize myself with the scripting in Klayout, they weren't anyhow similar to what I would like to achieve by this.

Thank you.


  • @MoBe

    We there is nothing special about multi-layer layouts.

    Whenever in a script something like this is done:

    l1 = layout.layer(1, 0)

    it means a new layer is created. In this case with GDS layer 1, datatype 0. "l1" is a variable which will hold an identifier for this layer (in fact an integer number). You use it in "Cell#shapes(layer_id)" for example to address a specific layer.

    You can create as many layers as you like provided the GDS layer or datatype number differ:

    # create two layers: 1/0 and 2/0
    l1 = layout.layer(1, 0)
    l2 = layout.layer(2, 0)
    # put a box to layer 1/0
    cell.shapes(l1).insert(pya.Box(0, 0, 100, 100))
    # put another box to layer 2/0
    cell.shapes(l2).insert(pya.Box(0, 0, 200, 200))


  • @Matthias I was just looking for some examples that I can follow to learn how to script for a layout. However, I have already started writing the script and am baby-step learning the details. Thank you for your amazing support here.

Sign In or Register to comment.