It looks like you're new here. If you want to get involved, click one of these buttons!
Is there any way to programmatically convert an OASIS file to a PNG image file? I know that within the UI I can open OASIS and then do File>Screenshot, but I'd like a way to do if from within Python if possible. Thanks!!!
Comments
There is a related discussion ongoing: https://www.klayout.de/forum/discussion/1711/screenshot-with-all-the-layer-and-screenshot-only-one-layer#latest
From there you can learn a lot about Python coded image generation scripts and it has a fancy version of a screenshot tool
If by "Python" you mean the Python module on PyPI, it also has a
LayoutView
class and can bascially do the same.Matthias
Thank you for your response Matthias! I should have explained my issue better. We will be running on a system without graphics support so are unable to open the Klayout UI. I'd like to be able to make calls to KLayout from the command line to perform the oasis to image conversion. Does Klayout expose this functionality outside of the UI? Thank you!!!
I'd advise to use the Python module. It provides a stripped-down version of the
LayoutView
class which can render OASIS to PNG without a graphics device.Just do
There is a demo web component (https://pypi.org/project/kweb/) that uses this technique to render layout on a HTTP server interactively through a WebSockets connection.
Matthias
Hi chrisl,
I hope the attached sample script from my toolbox will help you understand.
I have tested the code on Mac, Linux, and Windows 10.
Note: the [-c|--conf <KLayout's config file>] option is now effective. Replaced the attachment.
Sample Run
Kazzz-S
Cont.
How to reach LayoutView::load_layout()
Visit the URLs below sequentially:
1) https://www.klayout.org/klayout-pypi/
2) https://www.klayout.de/doc-qt5/code/index.html
3) https://www.klayout.de/doc-qt5/code/module_lay.html
4) https://www.klayout.de/doc-qt5/code/class_LayoutView.html
5) https://www.klayout.de/doc-qt5/code/class_LayoutView.html#method136
Cont.
Fixed a problem in Windows and re-attached the ZIP file (2024-08-06).
Sorry about the inconvenience.
Cont.
I found and fixed a fatal bug (cell hierarchy level is not checked), then re-attached the ZIP file (2024-08-07).
Sorry about the inconvenience once again.
Hi @sekigawa,
thank you very much for providing these scripts! It is very much appreciated
Just for my understanding - the fatal bug is not something inside KLayout, isn't it?
Thanks,
Matthias
Hi @Matthias,
The bug was not inside KLayout; I misused an API function.
Incorrect:
Correct:
Regards,
Kazzz-S
Very good. Thanks for the explanation!
Matthias
I will check it out! thank you so much @sekigawa and @Matthias!!!
@sekigawa I made a small change to remove the requirement for the layer file as I only have OASIS to work with and the images convert with no issue! Thank you so much! The converted image looks the same as the one imported via KLayout as hoped for!
Traceback (most recent call last):
File "D:\gds_to_image\oas2png-new.py", line 453, in
main()
File "D:\gds_to_image\oas2png-new.py", line 440, in main
ProcessOneOASISFile( configdic, item, count )
File "D:\gds_to_image\oas2png-new.py", line 278, in ProcessOneOASISFile
layoutview.load_layer_props( LayerPorpFile )
RuntimeError: Unable to open file: \gds_to_image\invKazzzS.lyp (errno=2) in LayoutViewBase.load_layer_props
Hello, I got this error, where is invKazzzS.lyp file?
You need to provide your own *.lyp for OASIS files.
If you want to trace the above sample run, please use the attached files.