get a cell, which contain specific layer only, and without others

I'd like to get a cell, which contain only contact (1:0), diffusion (2:0), metal1 (3:0). If the cell contain other layer(s), then don't get the cell.
e.g. other layer(s): (4:0), (5:0), (6:0)

I got the below code for find the specific cell I want, is there any easy way to check this stuff? Cause other layer(s) is much more than 3.

import pya

ly = pya.CellView.active().layout()
l1= ly.layer(1, 0)
l2= ly.layer(2, 0)
l3= ly.layer(3, 0)
l4= ly.layer(4, 0)
l5= ly.layer(5, 0)
l6= ly.layer(6, 0)
for c in ly.each_cell():
  l1_exi = c.shapes(l1).size() > 0
  l2_exi = c.shapes(l2).size() > 0
  l3_exi = c.shapes(l3).size() > 0
  l4_exi = c.shapes(l4).size() < 0
  l5_exi = c.shapes(l5).size() < 0
  l6_exi = c.shapes(l6).size() < 0
  l123 = ((l1_exi and l2_exi) and l3_exi ) 
  c1 = l123 and l4_exi
  c2 = l123 and l5_exi
  c3 = l123 and l6_exi
  if ( c1 or c2 or c3 == True):
    print(c.name)

BG,
KM

Comments

  • Hi,

    first of all there isn't a much better alternative.

    But you can code the search in a loop and end the loop as soon as the condition isn't satisfied. With a loop you can check as many layers as you like.

    In your code "size() < 0" does not make sense. size() cannot be less than zero.

    Here is a working example for a more generic code:

    import pya
    
    ly = pya.CellView.active().layout()
    
    required_layers = {
      ly.layer(15, 0): True,
      ly.layer(16, 0): True,
      ly.layer(17, 0): True
    }
    
    for c in ly.each_cell():
    
      failed = False
    
      for li in ly.layer_indexes():
    
        # to include subcells:
        # cell_is_empty = c.bbox_per_layer(li).empty()
        # to use only shapes inside this particular cell:
        cell_is_empty = (c.shapes(li).size() == 0)
    
        must_be_empty = True    
        if li in required_layers:
          must_be_empty = False
    
        if cell_is_empty != must_be_empty:
          failed = True
          break
    
      if not failed:
        print("Cell found: " + c.name)
    

    Please note the comment about subcells.

    Matthias

Sign In or Register to comment.