Getting absolute coordinates of boxes in python

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

iter =, cell,layer_index)  
            while not iter.at_end():
                Current_Shape=iter.shape() #Get the shape in the layer
                #print(Current_box.left) #LOWX_COORD
                #print(Current_box.bottom) #LOWY
                #print(Current_box.right) #UPX
                #print( #UPY

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!


  • 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
    # and use "klayout -b -rd input=yourfile.oas ... -r this_script.rb" to set $input
    RBA::LayoutQuery::new("select, path_trans * cell.bbox, path_trans.disp.x, path_trans.disp.y from instances of ...*").each(ly) do |q|
      puts { |d| d.to_s }.join("\t")


  • edited July 2020

    I answered my own question lol

    layout=pya.Layout()"select, path_trans * cell.bbox, path_trans.disp.x, path_trans.disp.y from instances of ...*")
    for q in a.each(layout):
  • 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


Sign In or Register to comment.