How to select the polygon pattern (waveguide or electrode path) which has the specific point?

edited August 2018 in Python scripting

Hi, I've been learning klayout with python scripting and can do something like drawing a simple pattern, inserting the subcell, and writing out. However, I want to "select" the existing path (like waveguide or electrode path with known layer and datatype, and only showing in the top cell) and "edit" it such as modifying the polygon points, extract the points , or delete it only with python scripting.

Would you please show me a simple python script how to "select" the polygon which includes the specific point (such as the highest point of the specific layer/datatype in the top cell) and "modify" it only with python scripting instead of UI?

Thank you

Comments

  • Hi,

    here is a short sample script. Please see the comments for details:

    lv = pya.LayoutView.current()
    cv = pya.CellView.active()
    ly = cv.layout()
    
    # take shapes from GDS layer 1, datatype 0
    layer_index = ly.layer(1, 0)
    
    # get the shapes container of the current cell of this layer
    shapes = cv.cell.shapes(layer_index)
    
    # search point in micrometer units
    pt = pya.DPoint(0.0, 10.0)  # JUST AN EXAMPLE
    
    pt_in_dbu = pya.CplxTrans(ly.dbu).inverted() * pt
    
    # undo/redo support
    lv.transaction("Modify polygon")
    
    for s in shapes.each_touching(pya.Box(pt_in_dbu, pt_in_dbu)):
      if s.is_polygon and s.polygon.inside(pt_in_dbu):
        # take polygon
        poly = s.polygon
        # modify it somehow (e.g. scale by 1.5)
        poly = poly * 1.5  # JUST AN EXAMPLE
        # store it back
        s.polygon = poly
        break
    
    # undo/redo support
    lv.commit()
    

    Matthias

  • Thanks for replying, I just noticed this comment.
    Thank you very much.

Sign In or Register to comment.