Hi, I am a new klayout user and just start to use python to so come coding work.
When I open a new and empty .lym file, what code I should input to get my goal? for example, I have a gds file named 123.gds.gz, its path is in "C:\Training\".
So is there a way to use python to read the gds file and export all the layer name as a .txt file?
Best wishes
Muheng
Comments
import pya
layout = pya.Layout()
layout.read('c:\Training\123.gds.gz')
for ly_id in layout.layer_indices():
ly_info = layout.get_info(ly_id)
print(ly_info.to_s())
then using klayout to load a.py like,
klayout -zz -r a.py
Thanks,
Dion
Thanks a lot, I am using windows PC, not Linux.
import pya
layout = pya.Layout()
layout.read('c:\Training\123.gds.gz')
for ly_id in layout.layer_indices():
ly_info = layout.get_info(ly_id)
print(ly_info.to_s())
When I use ur code, it shows an error:
line7: expected an indented block
line7 is the code "ly_info = layout.get_info(ly_id)"
Well, do u know what is the problem about that?
BTW,can u give me ur email address? so I can cut a picture and send to you, then you can have more details about my problem. I think something is wrong about my operation.
Thanks!
Muheng
Hi Muheng,
please use Markdown to format your code (four blanks in front of the line. Otherwise your code formatting does not become visible.
And please make yourself familiar with Python.
The code is:
Matthias
Cheers, Erwin
thanks a lot, now the code works!
I will keep on studying python and klayout
Best wishes
Muheng
I am using PyCharm to program python now in windows, one thing I am not familiar is the Klayout pya module.
Usually on the top of the python code, we can type the database which u want to import, for example
import xlwt
or
import pya
But when I open Pycharm, I think 1st I need to to let the Pycharm know that the library "pya", right? otherwise I think the code does not know the pya means.
Well, do u know how to setup in Pycharm and let it know pya library?
Best wishes
Muheng
Hi Muheng,
currently you cannot import pya as there is no such module. It's a function built into KLayout, so you need to work inside KLayout to get it. I'm working on providing such an external module, but it's only going to cover the geometry database part.
Matthias
oh, OK, thanks, Matthias
Hi Muheng, I very much look forward to Matthias's work of having a database module which can be used from a normal Python, but until then, you can still use PyCharm but you have to set the interpreter (in PyCharm) to be a windows batch file with the following content:
The debugger in PyCharm doesn't work this way but the syntax checking etc. does.
Best regards, Erwin