Home › Forums › Nazca › export cells into an existing gds › Reply To: export cells into an existing gds
Hello Ronald,
Yes I think that it does cover it, because in a normal use case I would instantiate the new cells as top cells and then instantiate them in the hierarchy manually in Klayout (usually by replacing old cells).
import nazca as nd
# Level 1 Cells
with nd.Cell(name='B') as cellB:
nd.strt().put()
with nd.Cell(name='C') as cellC:
nd.bend(angle=90).put()
with nd.Cell(name='D') as cellD:
nd.taper(layer=2).put()
# Level 0 Cell (top cell)
with nd.Cell(name='A') as cellA:
cellB.put()
cellC.put(10)
nd.export_gds(filename='example.gds', topcells=cellA)
# Load example.gds, and add cellD as a top cell
cell_dict = nd.load_gds(filename='example.gds',
asdict=True,
topcellsonly=True)
cell_list=list(cell_dict.values())
cell_list.append(cellD)
nd.export_gds(filename='example.gds', topcells=cell_list)
In the example above, I could either manually instantiate cell D as a new cell in cell A, or replace of the existing cells by cell D after the second export.
To push things further how could I automatically replace the cells in Nazca? In the example below I tried to replace cell C with a new version in the cell dictionary. It does not replace the old cell but instantiate it as a new top cell.
import nazca as nd
# A new version of cellC
with nd.Cell(name='C$1') as newC:
nd.bend(angle=30, layer=3).put()
# topcellsonlly flag set to False to import old cell C
cell_dict = nd.load_gds(filename='example.gds',
asdict=True,
topcellsonly=False)
# replace cell C in cell_dict
cell_dict['C'] = newC
# get new list of cells
cell_list=list(cell_dict.values())
nd.export_gds(filename='example_v2.gds', topcells=cell_list)
The obvious answer would be to recreate the whole hierarchy, i.e in this case:
newCellA
newCellC
oldCellB
oldCellD
But this can get tedious if you need to replace a cell in the lowest level of the hierarchy, or even worse if the cell is instantiated in different ‘tree branches’.
Thanks,
Paul
nazca version: 0.5.7