Producing a png image of a certain region in the layout using python.

edited April 2020 in Ruby Scripting

Hello I am a new member, so sorry if I unintentionally violate any discussion rules.

Edit: Ooops, I have noticed that I accidently opened this discussion in Ruby scripting. Is there way to delete this discussion? I will open the same in python scripting. Sorry!

I am trying to produce a png image of a certain region in the layout using python.
1-I need to read the .oas file,
2-Define the region of interest,
3-Create a png image of that region.

I searched through other discussions (https://www.klayout.de/forum/discussion/327/goto-position-and-snapshot)
and I think I can do it by using

include RBA
app = Application.instance
mw = app.main_window
lv = mw.current_view

lv.save_image("image_file.png", 640, 480)

However, when I try to run this on python IDE in Klayout, I receive an error for "include RBA" as an undefined method.
I also tried it on Ruby IDE.

Could you please help me to write a script that will produce a png image of a certain region in the layout using python.

Thanks in advance!
Kind regards.

Comments

  • Python module is pya. See also sample scripts.

  • Oh yes ...

    This is Python. I have also added code to navigate to a certain window before shooting the picture.

    Matthias

    import pya
    
    # coordinates for the window to screenshot in µm
    l = -12.0  # left
    r = 5.0    # right
    b = -2.0   # bottom
    t = 7.0    # top
    
    app = pya.Application.instance()
    mw = app.main_window()
    lv = mw.current_view()
    lv.zoom_box(pya.DBox(l, b, r, t))
    
    lv.save_image("image_file.png", 640, 480)
    
  • Hello Matthias,
    Thanks a lot for the useful answer!

    There is just one more error I get which is
    'pya' has no attribute 'Application'

    Although I can use pya's most of the classes, my pya version doesn't support classes like Application or LayoutView for some reason.

    Is there a simple way I can fix it? I used "pip install pya" from command prompt of my windows to install it. (Also installed pya from pycharm IDE- from settings, import package)- But still doesn't work.

    Also, I tried to find it from Anaconda navigator to add it to my virtual environment but couldn't see the package there.

    Thank you!

Sign In or Register to comment.