Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How to find cell instances that intersect with a box

Hi, I'm becoming fairly familiar with the python API and my question is about a strategy within the API calls to achieve a goal.

I want to know the leaf cell instances that intersect with a given box. I'm getting there right now by selecting the shapes that intersect with that box and creating a RecursiveShapeIterator (called shape_iterator below).

instance_path = shape_iterator.path()
last_cell_inst = instance_path[-1].cell_inst()

This runs once per shape instead of once per cell instance, so I'm wondering if I could improve the performance by navigating the hierarchy tree instead of the shapes themselves.

I originally tried to start with the top cell and select cells that intersected with the box, but it only returns cells in the top cell itself which doesn't give me my leaf cell information. Is there a strategy that would allow me to find the cell instances without processing every shape?

Many Thanks for any guidance you can provide.


  • Hi jpk,

    you can create a RecursiveShapeIterator from a cell with a search box. This will then return only the shapes within this box (seen from the initial cell) and only traverse the subcell instances inside this box.

    Is this what you are looking for?


  • The RecursiveShapeIterator solution is what I'm doing currently. Since it runs at the "shape" level, I'm guessing that it might run faster if I could traverse just the instance hierarchy information without having to query for every shape that exists inside the search box.

    I guess I'm looking for something like RecursiveShapeIterator but more like "RecursiveInstanceIterator" that will return a stream of cell instances that are inside the search box instead of shapes.

  • Hi jpk,

    I see your point.

    Internally there is such a thing, but not on the script level. It's a method called "skip_instance" which you can call to jump to the next instance. I have not considered yet to expose it to Python because I could not imagine a use case.

    Without this, you can emulate the whole procedure in Python, but I guess it will awfully slow.

    As a workaround it might be possible to define a dummy layer and place a rectangle with the dimension of the cell's bounding box for each cell. Then there is a single shape per cell and iterating over this layer will give you each instance once.



Sign In or Register to comment.