Trying to create script to trace around all polygons in a layer

I am attempting to create a script to produce a trace around each polygon in a layer and output it onto another layer. I use these traces with boolean operations to resize fill zones for fabrication. I expected this to be easy but I am running into issues generating a list of dpoints for each polygon.

My current code looks like:
import pya

layout_view = pya.Application.instance().main_window().current_view()
cell_view = layout_view.active_cellview()
layout = cell_view.layout()
viewed_cell = cell_view.cell
trace_width = 2.0

metal_layer = layout.layer(1, 0)
trace_layer = layout.layer(3, 0)

polygon_vertices = []

for shape_obj in viewed_cell.each_shape(metal_layer):
  polygon_vertices = shape_obj.each_dpoint
  viewed_cell.shapes(trace_layer).insert(pya.DPath(polygon_vertices, trace_width))
  polygon_vertices = []

Clearly I am misunderstanding how each_dpoint works. I currently don't have to worry about the polygons containing holes if that matters, though I would like to know how I should adapt if they do.

Thanks,
Zach

Comments

  • edited December 2023

    Hi @zlnelson,

    I think this is easier in DRC language.

    My approach would be that:

    trace_width = 1.um
    
    metal_layer = input(1, 0)
    
    trace_layer = metal_layer.sized(0.5 * trace_width) - metal_layer.sized(-0.5 * trace_width)
    
    trace_layer.output(3, 0)
    

    Matthias

  • Hi zlnelson,
    as your case, do you have any concern for that around trace must be a "path" type or "polygon" type is fine?

  • edited December 2023

    Hi zlnelson,

    If traced by path is required, then you can tryout this example.

    each_point type functions works like a python generator, you'll need to loop through them and collect all items into a list object before assigning to a DPath.

    And each_dpoint only works when your Shape object is a Path, which might not suits your need, if your are tring to trace polygons.

    Use shape.each_dpoint_hull instead to get vertices from the out line of an object

    for shape_obj in viewed_cell.each_shape(metal_layer):
        hull_points = [p for p in shape_obj.each_point_hull()]
        hull_points.append(hull_points[0]) #insert first point to close the trace
        viewed_cell.shapes(trace_layer).insert(pya.DPath(hull_points, trace_width))
    
Sign In or Register to comment.