Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Search and Select cells in a given area

edited October 10 in KLayout Support

In the windows "Search And Replace", in the "custom" tab, I think that we can select all the instance of a cell given by its name (i.e. AND3) in a given area given by its 4 extreme coordinates X1, Y1, X2, Y2 .
But what is then syntax ?

instances of cell TOPLEVEL.* where cell_name ~ "AND3" where ...

Thank you, Best regards,
Laurent

Comments

  • Hi Laurent,

    the syntax is:

    instances of ...* where (cell.bbox.left == -200 && cell.bbox.right == 1340 && cell_name ~ "SPARE")
    

    -200 is the left coordinate of the bounding box, 1340 the right one etc. All coordinates are given in database units.

    Matthias

  • And how to all of select them ?

    Thanks,
    Laurent

  • edited November 18

    And how to all of select them ?
    Actually, I need to select all the cells beginning with "xyz_" and flatten them :)

    Thanks, BRgds,
    Laurent

  • There is no "select found objects" yet. Sorry.

    Matthias

  • edited November 23

    I tried to write a macro, but I don't know how to flatten an instance :

    Best regards,
    Laurent

    include RBA
    
    lv = RBA::Application.instance.main_window.current_view
    lay = lv.cellview(lv.active_cellview_index).layout
    top = lay.cell("toplevel")
    
    
    top.each_inst  do |c1|
    cname = c1.cell.name
      if (cname[0..2] == "VIA")
        c1.flatten(8)
      end
    end
    

    But I got an error :

    Internal error: ../../../src/tl/tl/tlReuseVector.h:277 mp_v->is_used (m_n) was not true in Instance::cell
    
  • edited November 26

    Hi Laurent,

    in general it's not safe to iterate a collection (instances) while manipulating it (implicitly done in 'flatten').

    Hence this is the code I'd recommend. It's collecting the instances to delete in a first pass and then doing the flatten in a second one:

        lv = RBA::Application.instance.main_window.current_view
        lay = lv.cellview(lv.active_cellview_index).layout
        top = lay.top_cell
    
        insts_to_flatten = []
        top.each_inst  do |ci|
          cname = ci.cell.name
          if (cname.start_with?("VIA"))
            insts_to_flatten << ci
          end
        end
    
        insts_to_flatten.each do |ci|
          ci.flatten(8)
        end
    

    Matthias

  • Thank you Matthias !
    Collecting the instances before also allows to add a very useful Progress bar :

    lv = RBA::Application.instance.main_window.current_view
    top = lv.active_cellview.cell
    
    insts_to_flatten = []
    top.each_inst  do |ci|
      cname = ci.cell.name
      if (cname.start_with?("VIA"))
        insts_to_flatten << ci
      end
    end
    
    progress = RelativeProgress::new("Flattening #{insts_to_flatten.length} instances ...", insts_to_flatten.length)
    begin
    
      insts_to_flatten.each do |ci|
        ci.flatten
        progress.inc
      end
    
    ensure
      progress.destroy
    end
    

    Laurent

Sign In or Register to comment.