Home › Forums › Nazca › Questions and Answers › Select/delete objects in a cell with a size smallerthan x › Reply To: Select/delete objects in a cell with a size smallerthan x
Dear Cameron,
The best way to go about is to use the cell_iter(). It can dissect a Cell and rebuild it. This example shows an extended version where you can filter any cell element. In your case you can rebuild your gds but filter specific polygons, as indicated with the upper case remark:
# Nazca-0.5.12
import nazca as nd
gds = 'your_file.gds'
mask = nd.load_gds(gds)
ly = nd.layout(layermap={}, layermapmode='all')
for params in nd.cell_iter(mask):
if params.cell_close:
ly.close()
continue
if params.cell_create:
ly.open(params=params)
for pgon, xy, bbox in params.iters['polygon']:
# xy and bbox coordinates are w.r.t. first instantiated parent
# SELECT HERE WHICH POLYGONS YOU WANT TO ADD:
if < size of positions in xy > 5x5 >:
ly.add_polygon(points=xy, layer=pgon.layer)
else:
print(f"polygon {xy} has been filtered out.")
for pline, xy, bbox in params.iters['polyline']:
# xy and bbox coordinates are w.r.t. first instantiated parent
ly.add_polyline(points=xy, layer=pline.layer)
for anno, pos in params.iters['annotation']:
ly.add_annotation(text=anno.text, layer=anno.layer, pos=pos)
for inode, [x, y, a], flip in params.iters['instance']:
ly.add_instance(inode=inode, trans=[x, y, a], flip=flip)
ly.put()
nd.export_gds(filename=gds[:-4]+'_rebuild')
If you know that your polygons that you want to filter are in a specific layer, you can use that too (I reversed the logic a bit compared to the example above):
if pgon.layer == nd.get_layer(<layer>) and < size of positions in xy < 5x5 >:
print(f"polygon {xy} has been filtered out.")
else:
ly.add_polygon(points=xy, layer=pgon.layer)
The get_layer() is to make sure you get the layer ID regardless if you use the layer numbers or layer names. pgon.layer contains the layer ID as well.
Ronald