Retrieving vias in a zone

edited December 2020 in Python scripting

I am trying to retrieve the center point of all the vias (being represented by a box on a specific layer, say e.g. (17,0)) in a specific region of a layout.

I am using the following code that looks recursively for all the cells under a main cell that have shapes on the layer containing the vias:

via_centers = set()

shapes_iterator = main_cell_view.cell.begin_shapes_rec_overlapping(via_layer_index, target_bbox)

while not shapes_iterator.at_end():
shape = shapes_iterator.shape()
via_centers.add((shape.box_center.x, shape.box_center.y))

First, I get much less shapes than vias drawn of the vias layer.

Second, I noted that some shapes with the same center point are returned several times. To keep only one of these points, I had to use a Python set for the via_centers variable.

Third, the center point of the returned shapes (after transformation from relative to absolute coordinates) do not match with the coordinates of the actual vias.

For sure, I'm doing something wrong. But what?

Any idea?

Many thanks for your help.


  • edited December 2020

    I made several errors. Finally, the following code worked for me:

    via_centers = []

    shapes_iterator = main_cell_view.cell.begin_shapes_rec_overlapping(via_layer_index, tile_bbox)
    while not shapes_iterator.at_end():
        via_bbox = shapes_iterator.shape().polygon.transformed(shapes_iterator.trans()).bbox()
        via_centers.append((via_bbox.p1.x + round(via_bbox.width() / 2), via_bbox.p1.y + round(via_bbox.height() / 2)))


  • edited December 2020


    I think that your code could be simplified:

    while not shapes_iterator.at_end():
         via_bbox_center = shapes_iterator.shape().polygon.transformed(shapes_iterator.trans()).bbox().center()
        via_centers.append(via_bbox_center.x, via_bbox_center.y)


  • @ahmedo Yes, that's correct. The problem is that the iterator will give you the original vias with the placements inside their local cell. You'll need to transform them into the initial cell so they appear as they are seen from the top.

    The transformation can be simplified a little, because it's sufficient to just transform the center point:

    via_bbox_center = shapes_iterator.trans() * shapes_iterator.shape().bbox().center()


Sign In or Register to comment.