Howdy, Stranger!

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

Retrieve xy coordinates of selection


I wish to retrieve the actual xy coordinates of a selected shape. On the forum, there are several examples where a recursive search is used (top down) to retrieve the associated transformation. In this case however, this takes too long and I'd like to implement a bottom up approach. Unfortunately, the code only works partially:

lv = pya.LayoutView.current()
ly =
s = next(lv.each_object_selected()) # Only the first selected object 

tran = search_tran(s.shape.cell) 
point = shape.polygon.transformed(tran).point_hull(0)   

def search_tran(child_cell):
  cell = child_cell
  tr = []

  while not(cell.is_top()):
    cellinst = next(cell.each_parent_inst()).inst()     # Consider first element
    cell = ly.cell(next(cell.each_parent_cell()))       # go to parent

  tran = pya.CplxTrans()
  for k in range(len(tr)-1, -1, -1):
    tran = tran*tr[k].invert()

  return tran

The problem is with the line containing cellinst. I'm not sure how to decide which instance to extract that belongs to the shape.


  • I think I found it. The absolute transformation of the selection is already contained in s.trans(). This gives the following code, which is able to extract the name of a selected shape.

    import pya
    import math
    lv = pya.LayoutView.current()
    ly =
    dbu = ly.dbu
    shape = None
    cell = None
    s = next(lv.each_object_selected())
    cv = lv.cellview(s.cv_index)
    shape = s.shape
    if shape:
      tech = pya.NetTracerTechnology()
      tech.connection("31/0", "51/0", "32/0")
      tech.connection("32/0", "52/0", "33/0")
      tech.connection("33/0", "53/0", "34/0")
      tech.connection("34/0", "54/0", "35/0")
      tech.connection("35/0", "55/40", "36/40")
      tech.connection("36/40", "56/40", "37/60")
      tech.connection("31/0", "131/0")    # Labels
      tech.connection("32/0", "132/0")
      tech.connection("33/0", "133/0")
      tech.connection("34/0", "134/0")
      tech.connection("35/0", "135/0")
      tech.connection("36/40", "136/0")
      tech.connection("37/60", "137/0")
      point = shape.polygon.transformed(s.trans()).point_hull(0)
      tracer = pya.NetTracer()
      tracer.trace(tech, ly, ly.top_cell(), pya.Point(point.x, point.y), shape.layer)
      names = set()
      for element in tracer.each_element():
        if element.shape().text:
      pya.QMessageBox.information(None, "Net names", "Net name: %s\nAll names on net: %s" %(, names))
  • Hi,

    yes, exactly this is the right way to do it :-)

    I did not know about "next(...)". Thanks for this sample. This looks pretty useful.



Sign In or Register to comment.