It looks like you're new here. If you want to get involved, click one of these buttons!
Hello I am trying to use set_property to be able to add custom attributes to shapes and cells. When I try to add to shape it throws internal error (see screenshot). And when I try to add it via a cell, the attribute never shows up in the GUI (see second screenshot with empty key value pairs)
Can anyone see what am I doing wrong ?
Regards
EDIT: After a while I noticed that shape.set_property method should not be called inside a loop. When I move it outside the loop it stops throwing error. However I still can't see the property in the GUI. (key value pair in second screenshot is still empty)
# Enter your Python code here
import pya
layout = pya.Layout()
layout.read(r'input_file.oas')
top = layout.top_cell()
cell = layout.cell('hello_polygons_layer')
cell.set_property(1,2) #####does not have any effect
layer_index = layout.layer(1,4)
iterator = top.begin_shapes_rec(layer_index)
while not iterator.at_end():
shape = iterator.shape()
if shape.is_box():
print(shape)
shape.set_property('myattribute','best_shape') #####Gives Error:
iterator.next()
layout.write(r'output_file.oas')`
Comments
Hi @Ege_Bey,
"Cell#set_properties" has an effect for me:
gives:
What is your KLayout version?
Regarding the shape properties: you should not modify the shapes in the loop as changing the property may change the order of iteration.
Also, the recursive iterator may visit the same shape multiple times. You should use "called_cells" to collect the cells called from your initial cell and modify the properties in these cell's "shapes" container individually.
Matthias
Hi @Matthias
I just downloaded version 0.29.4,
tried the following code on the layout you see in screen shot. It didn't work unfortunately.
My user property is still empty
Do you have any other recommendations?
Hi @Matthias,
I could reproduce this problem as follows.
Preparations
troublesome_taper.oas
fromhttps://github.com/KLayout/klayout/issues/1793
.Using KLayout
0.29.4
(source build on Linux Mint 20.3), I saved it astroublesome_taper_new.oas
with the below options.Noticed that the file sizes differ.
Using troublesome_taper.oas
Using troublesome_taper_new.oas
I hope this helps you debug.
Best regards,
Kazzz-S
Hi @sekigawa
I tried your steps as well with the oas files you have attached.
1- I opened troublesome_taper.oas.
2- Saved as troublesome_taper_mytry.oas with the settings you have provided.
3- Opened troublesome_taper_mytry.oas and ran
Unfortunately user properties is still empty. Can it be platform dependent issue? I am using windows.
Regards,
Ege_Bey
Hi @Ege_Bey,
Thanks for testing.
I tried on
Windows 10 Enterprise
with...As you can see above, the results on Linux were reproduced. Are you using
Windows 11
?I'll also try on Mac later today.
Regards,
Kazzz-S
Cont.
On
macOS Monterey
with...The problem is reproducible.
Regards,
Kazzz-S
Hi @sekigawa,
Thanks for testing!
I am using windows 11 Enterprise
Cont.
Lastly, on
Windows 11 Home
with...In all my environments, the behavior seems consistent.
You're right. I can reproduce the problem with "troublesome_taper", but not with other files. Maybe it is only happening with a single cell per layout.
I will debug the problem. I have created a ticket for that issue: https://github.com/KLayout/klayout/issues/1799
Thanks for this nice breakdown of the problem.
Matthias
Thanks @Matthias
How can I keep track of the progress of the bug fix? (Like is there a way to watch the ticket and get notified when it is solved?)
Do you have any estimate on when it would be fixed?
Again many thanks!
Regards,
Ege_Bey
Just watch it ... it is already fixed. It is going to go into the next minor release.
The problem was an issue with the OASIS reader in certain cases.
Matthias
Perfect thank you for handling this issue so quick!
Very good. Thanks!
But even better: in case you need a real quick fix, you can pull the fixed sources from here: https://github.com/KLayout/klayout/tree/bugfix/issue-1799 and build a fixed version yourself. Difficult on Windows, easy on Linux
Matthias
Hi @Matthias,
Thanks for the quick fix.
I have tested the https://github.com/KLayout/klayout/tree/bugfix/issue-1799 branch.
All is OK on the three platforms.
Monterey
Mint 20.3
Enterprise
Regards,
Kazzz-S
Thanks for testing it!
A question came up to my mind. Will it also work when we run script outside of klayout IDE? I run most of my scripts outside of Klayout IDE. I just do pip install klayout and import pya to my script.
Hi @Ege_Bey,
Yes, we can run our script outside of the KLayout IDE.
However, we must install a patched *.whl (by
pip
) to address this issue.I've run the below script with the
(1) current release version
and(2) locally built version
of *.whl.Please wait for the
0.29.5
release or build it by yourself.I have no experience in building *.whl for Windows.
I have rebuilt a new *.whl (GH-1799) on my macOS Monterey with MacPorts.
Release
Regards,
Kazzz-S
Dear all,
I have merged to master already.
There are some wheels generated by GitHub here: https://pipelinesghubeus6.actions.githubusercontent.com/68A5NMsc4y2EbEDz38t9o9oKwhP9UxXzHEMhZ2QXBXaztmOIqM/_apis/pipelines/1/runs/1685/signedartifactscontent?artifactName=artifact&urlExpires=2024-07-27T19:42:14.0211820Z&urlSigningMethod=HMACV2&urlSignature=qKNYAJyy+kvO6BA4QosoKQP1MwTMZyMZoxU0LfOX7Po=
The version still is set to 0.29.4, but the code is taken from master.
Plus there are fresh builds from the master branch here (PRM, DEB, Windows .exe): https://www.klayout.org/downloads/master/
Matthias
Hi @Ege_Bey,
KLayout
0.29.5
is out.I've confirmed that the above
forum2552-S.py
script also runs as expected withklayout-0.29.5-cp311-cp311-win_amd64.whl
.Regards,
Kazzz-S
Thanks a lot for the effort and taking the time!!
Regards,
Ege