It looks like you're new here. If you want to get involved, click one of these buttons!
I follow such steps: Edit -> Layer -> Merge
Then I can merge layers.
However, I want to automate this process by using Macro Development. I'd like to know which class or procudure I should use.
Comments
Hello,
You can do that easily in the DRC environment (Macro Development > DRC):
https://www.klayout.de/doc-qt5/manual/drc_basic.html
https://www.klayout.de/doc-qt5/about/drc_ref_layer.html#h2-1534
layer.merge([overlap_count])
Cheers,
Tomas
@tomas2004 Thanks for the answer
I agree, but like to add you need to write it too ... so the above example equals to the DRC one-liner:
("merge" as a method will merge a copy of the layer, not the layer in the database).
Matthias
@Matthias Thank you soooo much!
@tomas2004 Thanks!!! It helps a lot.
I want to add 'Hierarchy' "Individually for current and subcells (semi hierarchical)" to
input(2, 0).merged.output(2, 0),
as the image below:

Then, I can merge automatically specific layers for multiple cells at the same time.
Thanks...
Hi @Wanchus,
Please consider opening a new discussion rather than reusing an old one.
The option you ask for is not available in the DRC language. It is a special option for the UI feature.
You can try using deep mode:
This will leave the merged shapes inside the subcells unless the shapes merge with geometry from outside the subcells. In that case, deep mode will propagate the merged shapes into the top cell.
Matthias
Hi @Matthias,
Thank you. Sorry for the late reply. Is there a way to stop the merging 'propagation' with geometries outside the subcells?
Thanks,
Wanchus
Hi @Wanchus,
not with DRC as DRC is follows the "as if flat" paradigm - i.e. what matters is the top-level view, not the details. Merged shapes are put as low in the hierarchy as possible, but are guaranteed to be non-overlapping.
"cell-local" merge for a specific layer can be achieved with this small Python script which even has undo:
Matthias
Hi @Matthias,
Thank you so much for the Python script example and sorry for the late reply.
Cheers,
Wanchus