Layer operations without flattening

edited October 2015 in Ruby Scripting
Hi Mathias, first of all thank you so much for such an amazing tool.
I am learning to write scripts to do simple operations to layers. However, everything I output goes to the top layer.
The simplest thing I would like to do is so trivial, just copy a layer and paste it in a different layer. I can easily do it from the menu, selecting the "cell by cell" option.
However, when I do it with script using "input" and "output", everything goes to the top layer, spoiling my hierarchy.

I know that for boolean operations, it makes sense that the software flattens everything before doing anything. But the simple operations I want to do should not have inter-cell overlapping problems. For example, if I could go cell by cell exploring at all depths, and finding only cells that have a certain layer as an element not as a child, my problem would be solved. Something like a "shallow select" or shallow "input". Is there anything like that?
Thanks!

Comments

  • edited November 2015

    Hello,

    Thanks for your feedback.

    Regarding your question about preservation of hierarchy: I guess you are referring to the DRC scripting. That is just one way of script things. The other way is more versatile, more powerful and slightly more difficult to use: the pure scripting API.

    Using that API you can do a simple shape-by-shape, hierarchy-preserving copy this way:

    ly = RBA::CellView::active.layout
    
    # copy layer 1/0 to 10/0. Both layers must exist.
    src = ly.find_layer(1, 0) || raise("Layer 1/0 not found")
    target = ly.find_layer(10, 0) || raise("Layer 10/0 not found")
    
    ly.copy_layer(src, target)
    

    There is much more to discover here. That scripting feature allows you to work on the lowest shapewise level up to the more abstract level that the DRC feature employs.

    A starting point for learning to code Ruby scripts is http://www.klayout.de/doc/programming/index.html.

    Matthias

Sign In or Register to comment.