save layer properties without losing the layer colors from script

edited May 21 in Python scripting

Hello,

Every time I try to save layer properties by using lv.save_layer_props(), it resets the layer colors. I know that I can first save layer properties from gui then load it via script. However, I directly want to inherit layer properties from the gui via python scripting. Is it possible? Thanks in advance!

app = pya.Application.instance()
mw = app.main_window()
mw.load_layout(layout_path,0)  #load the layout to the mainwindow so that you can see it
lv = mw.current_view()

lyp_path = os.path.join(directory,layer_property_file_name + ".lyp")  
lv.save_layer_props(lyp_path)   #Saves layer properties into the directory defined in lyp_path RESETS THE COLORS :(

Comments

  • Hi,

    "save_layer_props" will not reset the layer properties. But "load_layout" will do so, because it replaces the layout with a fresh one.

    You can replace a layout in a view by a new one while maintaining most of the settings, but not without some precaution:

    lv = pya.LayoutView.current()
    lv.cancel()
    
    # Gets the current layout
    cv = pya.CellView.active()
    ly = cv.layout()
    
    # Important: reset the cell so the view won't get confused
    # in case of an error
    cv.cell = None
    
    # Empty the layout and read a new one
    ly.clear()
    ly.read("new.gds")
    
    # Picks the top cell as the new active cell
    cv.cell = ly.top_cell()
    
    lv.zoom_fit()
    

    However, there are many details to add here: like how to maintain the cell selection, how to maintain cell visibility, whether to clear rulers or not, whether to select more or less hierarchy levels, error handling etc.

    Matthias

  • Thank you!

Sign In or Register to comment.