automating: find (x,y) locations of certain shapes

edited February 2014 in Ruby Scripting
Hello,

I need to find the (x,y) coordinates of certain shapes drawn in a certain layer. These (x,y) coordinates are all the positions of all the shapes inside the top cell; the shapes can be in subcells or arrays.
The work flow I currently use is as follows: with the top cell as the top view, I merge the specific layer. In this way, the data on the layer is also flattened. Next, I use the "Search and Replace" function to Find shapes on that specific layer and export the result to a .csv file. With this data I compute the shape centers.
I would like to automate this in a macro or script. Could it be that this kind of functionality is already available or if not, could someone point me to a good starting point and efficient methods I should be using. should I recursively search through the cell hierarchy or also code some sort of 'merge layer' step.
In addition, it would be nice to also store a screenshot(.png file) of the GDS layout around every found shape.

many thank!!

Comments

  • edited February 2014

    Hallo,

    Code for generating a screenshot can be found here: http://www.klayout.de/useful_scripts.html#screenshot.lym

    Fetching the shapes is easiest with the RecursiveShapeIterator object:

    ly = RBA::CellView::active.layout
    layer = ly.layer(8, 0)    # TODO: enter layer, datatype
    topcell = ly.top_cell
    
    iter = ly.begin_shapes(topcell, layer)
    while !iter.at_end?
      # Example: list all texts 
      if iter.shape.is_text?
        t = iter.shape.text.transformed_cplx(iter.trans)
        # t is the text transformed into the top cell:
        puts "pos: "+(t.trans.disp.x*ly.dbu).to_s+","+(t.trans.disp.y*ly.dbu)
      end
      iter.next
    end
    

    The RecursiveShapeIterator just delivers the shapes plus a transformation which transforms the shape into the top cell. It does not do the merging. To iterate, merge and flatten, the following code can be used:

    ly = RBA::CellView::active.layout
    layer = ly.layer(8, 0)    # TODO: enter layer, datatype
    topcell = ly.top_cell
    
    r = RBA::Region::new(topcell.begin_shapes_rec(layer))
    r.merge
    r.each do |p|
      # p will be a merged polygon transformed into the top cell:
      puts p.to_s
    end
    

    Beware that calling "merge" on huge layouts may take some time and require some memory. In addition, "merge" will not maintain shape identities (paths are converted to polygons) and texts will be omitted. If you want to exploit the shape identity, the above code is the better choice.

    Matthias

Sign In or Register to comment.