Python script for drawing box with increasing rotated angle

edited February 2021 in Python scripting

Hello, sirs

I am new to python script, and trying to create a layout with a rectangle box: 30 x 50 um ,
then make duplicates by pitch 80 um & rotating clockwise 0.5 degree till degree 60. ( It will include 121 rectangle rectangle boxes.. )
but, I am not familiar with Ruby code explanation in Klayout , will appreciate if can share some idea, thanks. :smile:

import pya
layout = pya.Layout()
Top = layout.create_cell("Top")
metal = layout.layer(1, 0)

width = 30 * 1000
height = 50 * 1000
pitch = 80 * 1000

leg0 = Top.shapes(metal).insert( pya.Box(0, 0, width, height) )
leg1...
leg2...
leg3...
...
..
.

leg121

layout.write("test.gds")

Comments

  • This is Python :)

    Try this:

    import pya
    
    layout = pya.Layout()
    
    top = layout.create_cell("Top")
    metal = layout.layer(1, 0)
    
    width = 30.0
    height = 50.0
    pitch = 80.0
    angle_delta = 0.5
    
    for n in range(0, 120):
    
      box = pya.DBox(0.0, 0.0, width, height).moved(-width / 2, -height / 2)
      # Only polygons can be rotated
      poly = pya.DPolygon(box)
      poly = pya.DCplxTrans(1.0, angle_delta * n, False, pitch * n, 0.0) * poly
    
      top.shapes(metal).insert(poly)
    
    layout.write("discussion1749.gds")
    

    Matthias

  • Hello, Matthias

    Thanks for sharing, This code enlightened someone like me as a beginner. :smile:
    Klayout is awesome.

Sign In or Register to comment.