Home › Forums › Nazca › Polygon clipping with interconnects › Reply To: Polygon clipping with interconnects
Dear Weiming,
Your question needs a slightly more elaborate answer in case of reading polygons from interconnects. Take the following example based on your code:
import nazca as nd
ic1 = nd.interconnects.Interconnect(width=2.0, radius=20)
bend_instance = ic1.bend(angle=45).put()
print(bend_instance.cnode.cell.polygons)
# prints an empty list: []
The polygons you are after seem at first sight to be located in the ‘polygons’ attribute of the cell that the bend instance (here named ‘bend_instance’) is based on. To get to the cell object we have to look it up via the cnode (the “cell master node”) that is stored in the instance: bend_instance.cnode.cell. However, there are no Polygon objects there (capital P to denote it is a class), i.e. the polygon attribute is an empty list of Polygons: [].
The catch is that the polygon that describes the bend geometry actually resides in a cell two levels deeper in the Nazca tree, but this is simplified in the gds export.
—
Your easy way out is the ‘cell_iter’ method. The following example prints all the polygon points [(x1, y1), (x2, y2), …] in instance ‘bend_instance’ regardless of the level.
cell_iter = nd.cell_iter(bend_instance)
for params in cell_iter:
if params.cell_start:
for pgon, points, bbox in params.iters['polygon']:
print(points)
Actually, the Polygon object ‘pgon’ by itself already contains all polygon information, including the points, bounding box and layer information. Try replacing ‘print(points)’ by the line below to see how that works
print(f"layer: '{pgon.layer}'\npoints: {pgon.points}\n")
Ronald