Getting absolute coordinates of boxes in python

Hello, is there a way to get the absolute coordinates of the boxes?

iter = pya.RecursiveShapeIterator.new(layout, cell,layer_index)  
            while not iter.at_end():
                Current_Shape=iter.shape() #Get the shape in the layer
                Current_box=Current_Shape.box
                #print(Current_box.left) #LOWX_COORD
                #print(Current_box.bottom) #LOWY
                #print(Current_box.right) #UPX
                #print(Current_box.top) #UPY
                x_coordinates.extend([float(Current_box.left),float(Current_box.right)])
                y_coordinates.extend([float(Current_box.bottom),float(Current_box.top)])
                iter.next()

I want to store the absolute x and y coordinates (accumulated transformations) of every polygon at a particular cell. This code only gives me relative coordinates.
Is there a way to get the absolute coordinates?

Thank you!

Comments

  • I found the answer as ruby code but having hard times to translate it into python.
    I would really appreciate the help. :)
    Thank you!

    ly = RBA::CellView::active.layout
    # for batch mode save this text to "this_script.rb" and use
    #  ly = RBA::Layout::new
    #  ly.read($input) 
    # and use "klayout -b -rd input=yourfile.oas ... -r this_script.rb" to set $input
    
    RBA::LayoutQuery::new("select cell.name, path_trans * cell.bbox, path_trans.disp.x, path_trans.disp.y from instances of ...*").each(ly) do |q|
      puts q.data.collect { |d| d.to_s }.join("\t")
    end
    

    source: https://www.klayout.de/forum/discussion/1175/extract-information-from-oasis-file#latest

  • edited July 2020

    I answered my own question lol

    layout=pya.Layout()
    a=pya.LayoutQuery.new("select cell.name, path_trans * cell.bbox, path_trans.disp.x, path_trans.disp.y from instances of ...*")
    for q in a.each(layout):
      print(q.data())
    
  • Very good! A role model user :)

    At the risk of frustrating you: you actually have been very close to the simple solution: the recursive iterator has a method called "trans()" which gives you the transformation from the current to the initial cell (the one from which you started the RecursiveShapeIterator):

    iter = ... # a Recursive Shape iterator 
    box_in_cell = iter.shape().box
    box_in_initial_cell = iter.trans() * iter.shape().box
    

    There is one detail that needs consideration: if your instantiation path contains instances with arbitrary rotation (e.g. 45 degree), the transformation is one that would turn a box into a different shape (a diamond for example).

    This is not achieved by multiplying the transformation with the box. If you need to consider this case in general, use polygons instead of boxes:

    iter = ... # a Recursive Shape iterator 
    polygon_in_cell = iter.shape().polygon
    polygon_in_initial_cell = iter.trans() * iter.shape().polygon
    

    Matthias

Sign In or Register to comment.