Home Forums Nazca rebuild cell Reply To: rebuild cell

#6040
Ronald
Keymaster

Dear Paul,

That is an interesting example. Only the last cell in the loop makes it to the final gds layout, because the rebuild reuses the normal export_gds() code base that by default clears all cells at the end. Two ways forward:

Solution 1:

In a call directly to export_gds() the clear setting can be changed by passing clear=False. The rebuild() does not have to clear keyword yet up and including 0.5.9. You can add it though by going into Nazca module layout.py and in def rebuild() add the line export.clear = False, somewhere before the line export.generate_layout(cell).

Solution 2:

Another way is to use the code to reconstruct cellA and not clearing any cells. In the example below I use nazca-0.5.9 to make use of the custom suffix option and some variable name improvements. Note that each new cell needs a new unique name. Below that is done using the layer number as a suffix.

import nazca as nd

with nd.Cell(name='CellA') as cellA:
    nd.strt(length=2, width=2, layer=0).put()

grid_points = [(0, 0), (4, 0), (0, 4), (4, 4)]

def custom_rebuild(cell, layermap, suffix="_new"):
    ly = nd.layout(layermap=layermap, suffix=suffix)
    for params in nd.cell_iter(cell):
        if params.cell_start:
            if params.cell_open:
                ly.cell_open(params)
            ly.add_polygons(params)
            ly.add_polylines(params)
            ly.add_annotations(params)
            ly.add_instances(params)
        elif params.cell_close:
            ly.cell_close(params)
    return ly.topcell

for i, (x,y) in enumerate(grid_points):
    new_cell = custom_rebuild(cellA, layermap={0:i}, suffix=f"_{i}")
    new_cell.put(x,y)

nd.export_gds()

Ronald