It looks like you're new here. If you want to get involved, click one of these buttons!
Hi,
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 = pya.CellView.active().layout()
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
tr.append(cellinst.cplx_trans)
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.
Comments
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.
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.
Regards,
Matthias