Layer properties (.lyp) file name

Hi Mattias,

Is there a way to define default layer properties file without specific file name?
I thinking about situation when we will have one .lyp file in the same directory as opening gds file and this .lyp file should be automatically loaded.
I was trying different combinations of special signs and .lyp extension (.lyp, "".lyp, "".lyp, .lyp etc.), but none of them work.
I don't want to have fixed name, as it can change in the different directories.
Do you think that it is possible?

Lidia

Comments

  • If you have set up a "Technology" then the name /
    path for the .lyp is one of the entries in the forms.

    Technology choice is "sticky" so should autoload
    until you change technologies or somehow lose
    the remembered settings.

  • edited December 2021

    You could script such a feature in KLayout, but it's probably easier to create a shell wrapper like this simplified one:

    #!/bin/env bash
    
    file="$1"
    shift
    
    klayout $file -l $(dirname $file)/*.lyp $*
    

    For a useful script you should at least add some error handling and sanity checks.

    Matthias

  • Thanks you both for response.
    I working on Windows, so this doesn't work for me.
    I was able to write basic Ruby script which adds lyp_import tab to the main window (in the Toolbar section).
    You need to click on it to load the lyp file (I also set this macro to run on start, so this tab is automatically added). Maybe it will be useful for someone else too (if there is more than one .lyp file the last one (sorted by name should be loaded).
    Here is the code:

    include RBA
    a = RBA::Action.new
    a.title = "lyp_import"
    
    file = Pathname("./").children(false)
    
    for x in file do
      if (x.to_s).end_with?(".lyp") then
        lyp_file = x.to_s
      end  
    end
    
    a.on_triggered do
      ly = LayoutView::current
      ly.load_layer_props(lyp_file)
    end
    
    menu = RBA::Application.instance.main_window.menu
    menu.insert_separator("@toolbar.end", "name")
    menu.insert_item("@toolbar.end", "my_action", a)
    

    Thanks,
    Lidia

  • @Lidia Very good! Thanks a lot for sharing this code!

    Kind regards,

    Matthias

  • Hello,

    I like this concept and extended it a bit:

    1) when there is only 1 lyp file in the layout directory, it will be loaded.
    2) when there are multiple lyp files in the layout directory, and one has the same name as the layout file, it will be loaded.
    3) else, you will be asked to select the lyp file you want.

    The script will appear in the "File" menu before "Close".

    Cheers,

    Tomas

    module MyMacro
    
        include RBA
    
    
        main_window = Application.instance.main_window
    
        layout_file = FileDialog.ask_open_file_name("Select Layout File", ".", "GDS files (*.gds *.GDS *.gds2 *.GDS2);;OAS files (*.oas *.OAS);;All files (*)")
    
        if !layout_file.empty?
    
            main_window.load_layout(layout_file, 1)
    
            layout_view = main_window.current_view
    
            layout_file_directory = layout_file.rpartition("/").first
    
            layout_file_name = layout_file.rpartition("/").last
    
            layout_lyp_file_with_same_name = layout_file_name.rpartition(".").first + ".lyp"
    
            Dir.chdir(layout_file_directory)
    
            lyp_files = Dir.glob("*.lyp")
    
            if lyp_files.size == 1
    
                layout_view.load_layer_props(lyp_files[0])
    
            elsif lyp_files.include? layout_lyp_file_with_same_name
    
                layout_view.load_layer_props(layout_lyp_file_with_same_name)
    
            else 
    
                lyp_file = FileDialog.ask_open_file_name("Select lyp File", ".", "lyp files (*.lyp)")
    
                if !lyp_file.empty?
    
                    layout_view.load_layer_props(lyp_file)
    
                end # if
    
            end # if
    
        end # if
    
    
    end # MyMacro
    
Sign In or Register to comment.