It looks like you're new here. If you want to get involved, click one of these buttons!
Hi, Matthias!
I tried to make multiple screenshots after changing layers/group visibility in script. Looks like LayoutView.update_content do not update view properly when group was not visible.
First screenshot taken for layer from visible group (Nested 1) is fine, but second, for layer from invisible group  (Nested 2), is empty.
Script is:
import pya
main_window = pya.Application.instance().main_window()
current_view = main_window.current_view()
for index in range(1, 3):
    suffix = f'{index}'
    for layer_properties in current_view.each_layer():
        layer_properties.visible = layer_properties.name.endswith(suffix)
        print(layer_properties.name, layer_properties.visible)
    current_view.update_content()
    current_view.get_image(800, 600).save(f'Screenshot.{index}.png')
It was run with KLayout 0.28.11 with attached session/layout: klayout -u Session.txt -r script.py
Comments
Hi EugeneZelenko
Add a
process_eventsbeforeget_imageshould able to solved this issueHi!
Thank your for help! It works!
But will be good idea to reflect this in documentation (
LayoutView.update_content?).Dear all,
Wasn't that an issue before somewhere?
"process_events" is required as it triggers the repaint event that actually does the rendering.
But basically "update_content" could imply "process_events".
Matthias
Thanks to the test case I could debug this issue and found a way to avoid the "process_events" call. This patch will be released in the next minor release. Even "update_content()" is no longer required.
Matthias
Hi, Matthias!
Thank you for quick fix! It'll really simplify end-user code.
I believe so
It's actually released yesterday. There is some background processing happening and the single-threaded synchronous get_image etc. methods now take care of finishing these tasks before they deliver the image data.
Thanks for reporting the problem and the nicely prepared test case.
Matthias
Hi, Matthias!
I tried to do such screenshots for multiple views opened in KLayout (with similar layer properties for each of them) and suggested workaround for 0.28.9 (
pya.Application.instance().process_events()) and your fix in 0.28.12 work only for current view. As workaround I preserve current view, iterate through all views, set new current view, make screenshots and restore current view at the end.However, it's not obvious why
LayoutView.get_image()behavior depends on view's activity status.Hi Eugene,
Thanks for bringing this up. I created a new ticket for this: https://github.com/KLayout/klayout/issues/1512
From the code perspective I think I understand why non-active views don't get updated. Maybe the following is a workaround:
Matthias
Hi, Matthias!
Thank you for help! Probably, issue could be not of high priority, because two workarounds are available.