It looks like you're new here. If you want to get involved, click one of these buttons!
Hello, I want to draw the same box to the same spot by using a for loop.
It may look unimportant but this is just the beginning of what I am trying to do.
First I will draw the same boxes at the origin. Then I will rotate the coordinates of the box by using a rotation matrix (It makes rotation easier when center is at 0,0) . Then I will translate them.
However when I try to draw it klayout just draws one object. I need three objects at the same spot.
layout=pya.Layout()
cell=layout.create_cell('TOP')
l_tl = 1
b_tl = 2
r_tl = 3
t_tl = 4
dbu=layout.dbu
layer = layout.layer(1, 0)
for i in range(0, 3):
cell.shapes(layer).insert(pya.Box(l_tl / dbu, b_tl / dbu, r_tl / dbu, t_tl / dbu)) # LOWLX, LOWLY, UPRX, UPRY
layout.write(oas_path)
This code doesn't give me three boxes at the same spot. Instead it just gives one box.
I don't understand why this is happening?Could you tell me what am I doing wrong?
Thank you!
Comments
I've got zero Python skillz, but I see nothing that would
(to me) increment "i" in the "for" statement, or say by
how much.
Maybe add a bit of "telemetry" such as an "echo $i" (per
whatever is Python syntax) to see whether the problem
is due to the behavior of the "for" construct, of with the
actual creation of the object.
You could also try just making three statements which
would do the same thing:
'''
cell.shapes(layer).insert(pya.Box(l_tl / dbu, b_tl / dbu, r_tl / dbu, t_tl / dbu)) # LOWLX, LOWLY, UPRX, UPRY
cell.shapes(layer).insert(pya.Box(l_tl / dbu, b_tl / dbu, r_tl / dbu, t_tl / dbu)) # LOWLX, LOWLY, UPRX, UPRY
cell.shapes(layer).insert(pya.Box(l_tl / dbu, b_tl / dbu, r_tl / dbu, t_tl / dbu)) # LOWLX, LOWLY, UPRX, UPRY
layout.write(oas_path)
'''
and see what happens there, as a diagnostic?
I wonder whether the "duplicate" command can be used
in your Python script? That is meant to make second, third, ...
in the same location. Maybe it works cleaner (if it is a
Python accessible function)?
I can draw three identical same layer, same vertex-set
boxes in the interactive klayout window no problem. So
it's not the core layout program preventing what you're
trying.
Hi,
The problem is writing to OASIS - I see your file name is "oas_file", so I assume this is the case.
OASIS is a special format which benefits extremely from shape compression (array detection, repetition detection etc.). The format is designed to exploit regularity, but not redundancy.
The same box three times is optimized away by the OASIS writer. This is a side effect of the repetition detection algorithm.
You should see the three boxes if you write to GDS.
Matthias