Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Moving set of layers

What is proper way to move set of layers (change their order) in Python? Or re-arrange cellviews order because in I need to move all layers belonging to particular cellview.


  • Hi,

    the solution depends on what you want to achieve.

    In any case I'd recommend to use the LayerIterator concept. "LayoutView#each_layer" isn't entirely stable for iterating while deleting (see

    Here is some sample code that moves all layer with even GDS layer numbers to the end:

    # Example: shuffle the layers so that even-numbered layers
    # move to the end.
    lv = pya.LayoutView.current()
    to_insert = []
    # Delete all layers with even layer numbers and keep their properties
    li = lv.begin_layers()
    while not li.at_end():
      if li.current().source_layer % 2 == 0:
        # keep the layer properties (dup LayerPropertiesNode) and 
        # delete the layer. isn't required as li will point
        # to the next entry anyway.
    # Finally insert the deleted layers at the end of the layer list
    for l in to_insert:
      lv.insert_layer(lv.end_layers(), l)

    Kind regards,


  • Hi, Matthias!

    Thank you for help! Similar code pattern (I used active_cellview.index() as criteria) solved my problem!

Sign In or Register to comment.