Array of rectangle in Parray


Hello,

I'm very new to Python language and KLayout. For a project, I need to generate a series of rectangles (each in the same or different layers) in KLayout using Macro development. This way, depending on the input/variable assignment from the user, say N, the program can generate N Rectangles and height and width can be adjusted for one rectangle and others will increase or decrease by a magnification factor. Pitch can be adjusted too. Please help me with this. A picture is added here.

Comments

  • This script does what you want. You need to edit the parameters to your liking:

    import pya
    
    N = 4
    
    view = pya.Application.instance().main_window().current_view()
    layout = view.cellview(0).layout() # You do not need this for this scrip...
    cell = view.cellview(0).cell
    
    for n in range(N):
        b = pya.DBox(pya.Point(n+0,n+0), pya.DPoint(10+2*n, 10+2*n))
        cell.shapes(0).insert(b)
    
  • edited December 2022

    Hi @soumeniit,

    Thanks for your interesting post. :)

    Your requirements do not seem simple to me, especially when all conditions are combined.
    If I were you, I would divide the problem into two components (divide-and-conquer approach):
    (1) design description captured in an Excel sheet or a similar (I prefer CSV)
    (2) manipulation of the design description by KLayout (macro)

    Please refer to the attached file set that conveys my idea.
    To be honest, I borrowed the idea from this post.

    I hope the Python code is self-explanatory.
    However, you need to carefully read the KLayout document (the built-in Assistance tool is handy).
    More specifically, the following Classes are crucial:
    (1) Layout
    (2) Cell
    (3) DBox
    (4) LayerInfo
    (5) MainWindow
    (6) LayoutView

    You can easily find various information and tutorials on Pandas.

    Good luck!

    Kazzz-S

    [Edit: 2022-12-20]

    • Remade KazzzS-KL2208.xlsx using Microsoft Excel (earlier, LibreOffice Calc)
  • I have modified incomplete usage descriptions.
    Sorry for the inconvenience caused.

    Kazzz-S

Sign In or Register to comment.