switch layouts but without losing the handle

Hi,

I would like to switch layouts but without losing the handle
I have the following example code:

mw = pya.Application.instance().main_window()
mw.create_view()
ly1 =  pya.Layout()
ly1.read( "design1.oas")
ly2 =  pya.Layout()
ly2.read( "design2.oas")
mw.current_view().show_layout(ly1, False)
mw.current_view().show_layout(ly2, False)
mw.current_view().show_layout(ly1, False)

on the last line I am getting the error: Object has been destroyed already for argument #1 ('layout') in LayoutViewBase.show_layout

I understand from it that layoutview.show layout is then destroying the previous design
is there a way to switch layouts views without destroying them?

Comments

  • No, there is no such switch. Currently, "show_layout" will pass the ownership over the Layout object to the view.

    But you can pass a copy:

    mw.current_view().show_layout(ly1.dup(), False)
    

    If that is deleted, your original layout is left intact. But the copy and your original layout are detached. Still it's an option to display a layout object.

    Matthias

  • Thanks, I then rather went for the duplicate before the switch. ie:

    mw = pya.Application.instance().main_window()
    mw.create_view()
    ly1 =  pya.Layout()
    ly1.read( "design1.oas")
    ly2 =  pya.Layout()
    ly2.read( "design2.oas")
    mw.current_view().show_layout(ly1, False)
    # edit layout ly1
    ly1 =  ly1.dup()
    mw.current_view().show_layout(ly2, False)
    # edit layout ly2
    ly2 =  ly2.dup()
    mw.current_view().show_layout(ly1, False)
    
Sign In or Register to comment.