Home Forums Nazca Questions and Answers Iterate over a cell and return polygons from child cell Reply To: Iterate over a cell and return polygons from child cell

#6592
Ronald
Keymaster

Dear garbagebag,

The example below should do what you described (extracting polygons and their position w.r.t. a top cell in a celltree).

The params is a namedtuple that contains both the translation and flip state of a cell instantiation with respect to its direct parent, as well as with respect to the top cell that is iterated over, i.e. “trench” in your example. The namedtuple keys to look for are transflip_loc and transflip_glob. Both are themselves a tuple of the form (Pointer, flipstate). Here “trans” stands for translation (in x, y, and a).

Because the iterator will initiate a loop on cell opening and again on cell closure, I added a check for some actions on cell_open is True only, in the example below, and save the xya position in the same manner as you did for the polygon points. Note that on cell closure the polygon iterator is an empty list, so in your initial example everything works just fine without checking for a cell_open condition.

``````import nazca as nd

nd.clear_layers()

with nd.Cell(instantiate=True, name='trench') as trench:
nd.strt(length=5, width=5, layer='tr').put(0, 0)
nd.strt(length=3, width=7, layer='tr').put()

trenchInstance = trench.put(0, -10, 10)

# search the trench cell for polygons
polygons = []
xya = []
for params in nd.cell_iter(trench, flat=False):
if params.cell_open:
trans, flip = params.transflip_glob
for pgon, xy, bbox in params.iters['polygon']:
if pgon.layer == 'tr':
polygons.append(xy)
xya.append(trans.xya())

for polygon, xya in zip(polygons, xya):
nd.Polygon(points=polygon, layer='tr').put(xya)

nd.export_gds(filename='forum_problem.gds')``````

Ronald