Howdy, Stranger!

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

how to extract polygons with specific number of points to a new layer?

Hi, Klayout team, this is my first post. I want to extract all the polygons with specific number of points and form a new layer. i tried to do it using DRC, but there is no command to get number of pts in the polygon. so i turned to ruby macro. However, i have some difficulties to output them into a new layer. here is my current code. Can someone help? thanks.

module MyMacro

include RBA

numPts = 64

ly = RBA::CellView::active.layout #active layout
lv = RBA::Application::instance.main_window.current_view
cell = ly.top_cell

#if lv == nil
# raise "No view selected"
# end

index = 0
lv.each_object_selected { |obj|
shape = obj.shape
if shape.is_simple_polygon?
if shape.polygon.num_points_hull == numPts
#extract the polygon or obj to a new layer
# need help here

  end
end

} #obj

end

Comments

  • updates: I am able to make most of the part work by creating a new layout and cells and insert the shape to the new layout. However, i still have one big problem. There are so many pads on the design, the coordinates are in relative system and the relative coordinates are the same. After i insert all of them, there is only one pad in the final output. In addition, i am not able to get the transformation information using shape.array_trans (All 0s). Can someone help?

  • Hello,

    your code is more readable if you use Markdown formatting and put a single line with a triple backtick before and after your code.

    You can use DRC for your purpose if you know that using the "data" method you can access each layer's underlying "Region" object:

    # DRC script which selects (raw) polygons with 64 points
    # CAUTION: this function will flatten the layer. It will convert paths to 
    # polygons and apply the filter then:
    
    num_pts = 64
    
    inp = input(6, 0)
    
    outp = polygon_layer
    inp.data.each do |p|
      p.num_points == num_pts && outp.data.insert(p)
    end
    
    outp.output(1006, 0)
    

    If you want to just find polygons with 64 points, you can also use the "Search and Replace" feature with this custom query:

    polygons on layer 6/0 from cells * where shape.polygon.num_points == 64
    

    Matthias

Sign In or Register to comment.