It looks like you're new here. If you want to get involved, click one of these buttons!
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.
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 https://github.com/KLayout/klayout/issues/368).
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. li.next() 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:
Thank you for help! Similar code pattern (I used active_cellview.index() as criteria) solved my problem!