Can we automate the process of merging layers?

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.


  • Hello,

    You can do that easily in the DRC environment (Macro Development > DRC):




  • @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:

    input(1, 0).merged.output(1, 0)

    ("merge" as a method will merge a copy of the layer, not the layer in the database).


  • edited July 2021

    @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.


  • edited May 11

    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:

    input(2, 0).merged.output(2, 0)

    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.


  • Hi @Matthias,

    Thank you. Sorry for the late reply. Is there a way to stop the merging 'propagation' with geometries outside the subcells?


  • 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:

    import pya
    ly =
    lv = pya.LayoutView.current()
      # undo support
      lv.transaction("Merge shapes")
      # Example: merge layer 14/0
      layer_to_merge = ly.layer(14, 0)
      for c in ly.each_cell():
        shapes = c.shapes(layer_to_merge)
        r = pya.Region(shapes)


Sign In or Register to comment.