Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

is there a way to write a script to load a list of locations and 'step through' through in klayout

edited December 2018 in Ruby Scripting

Hi

I am not sure if the following is possible.

I have a GDS file and a file contains a list of locations in the given GDS file. I would like to use klayout to load the GDS file, then somehow load the list of locations, and then "step through" (by clicking a button or use some short cut key) of each location. basically I want to move the klayout window to each of those locations. Is there a way to write a python script to do that?

Thanks

Comments

  • Hi,
    sure! This is possible! I hacked a snipped for you that allows you to cycle through locations by pressing Ctrl+n:

    import pya
    from itertools import cycle
    
    main_window = pya.Application.instance().main_window()
    current_view = main_window.current_view()
    
    # Load layout into new view
    path = pya.FileDialog.ask_open_file_name("Choose your file.", '.', "GDS2 (*.gds)")
    cell_view = main_window.load_layout(path, 1)
    
    # Load locations in microns
    # TODO: load locations from your file.
    #location_file = pya.FileDialog.ask_open_file_name("Choose your location file.", '.', "CSV (*.csv)")
    locations = [(0,0), (1, 1)]
    locations_iter = cycle(locations)
    
    current_view = main_window.current_view()
    
    # This function will be called when pressing Ctrl+n
    def step_forward():
      # TODO: Width/height of view
      w, h = 1, 1
      x,y = next(locations_iter)
      view_box = pya.DBox(x-w/2, y-h/2, x+w/2, y+w/2)
      current_view.zoom_box(view_box)
      print(current_view.box())
    
    # Register a menu item with callback and shortcut
    action = pya.Action()
    action.title = "step"
    action.on_triggered = step_forward
    action.shortcut = "Ctrl+n"
    
    menu = main_window.menu()
    menu.insert_item("tools_menu.end", "stepper", action)
    
    # Jump to first location
    step_forward()
    

    What you need to do is: create a new Python macro and paste the code into it. Further there are some TODOs in the code. You may want to change the lines near them. For instance you need to load your locations. I didn't know anything about the file format so I just put a dummy list of locations.

  • really appreciate it. I will try it.

    Thanks

  • I would use the Tools->Marker Browser that's used to load .rdb error files, it not only has "step thru" functionality, but also markers ..

  • Hi all,

    thanks for this lively discussion :-)

    The marker browser is exactly build for this purpose. If you're able to format the list of coordinates in it's XML format, you're done. It's also possible to fill a marker database using a script and show this one. There is a discussion where I explained how: https://www.klayout.de/forum/discussion/comment/786#Comment_786. This script is somewhat outdated now, but the RDB concepts are still the same.

    There is a screenshots gallery on the sample page: https://www.klayout.de/examples/screenshots.html. Maybe you like this way too. It's a graphical way to select a specific location.

    Matthias

  • edited December 2018

    Matthias

    Never mind. I found the description by using google:-) It's in https://www.klayout.de/rdb_format.html

    I will try to use the "Marker Browser". However, I didn't find the description of the rdb file format. Is there some description on the file format? a casual search didn't find anything

    Thanks
    Steven

  • Hi Steven,

    ver good :-)

    I wonder why Google won't find it - the RDB description is properly linked from the main page: https://www.klayout.de/rdb_format.html.

    Best regards,

    Matthias

Sign In or Register to comment.