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


As a second option you can flatten the celltree during iteration. The “xy” in the polygon iterator will always return the coordinates with respect to the first instantiated parent, which is the top cell in the iteration, here “trench”, because flat=True. In the example below I now use params.cell_start instead of params.cell_open, as the former will be True on any cell processed (instantiated or not), whereas the latter is only True if the cell will be instantiated. Depending on your needs cell_open or cell_start could be more useful, but here cell_open will not do the job due to the flat=True, which results in an instantiate=False state. As explained in my previous post you could even omit the check for cell_start completely here.

import nazca as nd

nd.add_layer(name='tr', layer=2)

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 = []
for params in nd.cell_iter(trench, flat=True):
    if params.cell_start:
        for pgon, xy, bbox in params.iters['polygon']:
            if pgon.layer == 'tr':

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