Home › Forums › Nazca › Questions and Answers › Select/delete objects in a cell with a size smallerthan x
Tagged: cell_iter, filter polygons
- This topic has 1 reply, 2 voices, and was last updated 3 years, 12 months ago by Ronald.
-
AuthorPosts
-
8 August 2020 at 14:54 #6224CameronMember
Hello,
I have created an array of squares on one layer with a layout software. First, I’d like to import this gds into nazca script. Next, I’d like to delete any elements from the array which are smaller than a certain size. For example, most of the squares in the array have a size which is 5 x 5. But some elements are smaller such as 2 x 3. I want to delete those small ones, creating or leaving behind an array with only the 5 x 5 square elements.
Pseudocode would be like:
import arrayfile.gds
select objects which are not 5 x 5
delete objects
export newarrayfile.gds
Sorry if my pseudocode isn’t helpful.
Thanks for your help in advance,
Cam
17 September 2020 at 21:34 #6238RonaldKeymasterDear 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
-
AuthorPosts
- You must be logged in to reply to this topic.