How to load Layouts from Links (Windows)

Given a Layout at: C\Users\whatever\layout.gds and creating a shortcut to it (Win: right-click -> create shortcut).
How can this shortcut be loaded?

import pya
path=r"C\Users\whatever\layout.gds"
# works
pya.Layout().read(path)
# does not work
pya.Layout().read(path + ".lnk")

The error I get is: RuntimeError: Stream has unknown format: ...lnk in Layout.read. Loading the .lnk file in KLayout GUI using File -> Open works fine however.
How can I load the shortcut in python similar to how it is done in the GUI?
Thanks! :)

Comments

  • edited April 16

    Hi @Peter123,

    I am sorry, but that is not supported natively.

    Unlike Unix, on Windows, a link (*.lnk) is not handled by the file system, but by the shell. A "lnk" file is a binary file, nothing more, so an application needs to be coded in some special way to support it (see for example https://stackoverflow.com/questions/54728510/how-to-follow-a-symbolic-soft-link-in-cmd-or-powershell#54732814). Apparently, the "Open" dialog resolves the "lnk" file to the destination.

    There is Python code available which resolves the links (https://github.com/strayge/pylnk/blob/master/pylnk3.py, pylnk3 module). You can copy pylnk3.py into c:\users\your_name\KLayout\python to make this module available. There is no thing such as "pip" in a standalone KLayout installation.

    Matthias

  • edited April 17

    Hello @Matthias,

    Thank you for the info. I learned a new technique today :smiley:
    I found I should copy pylnk3.py into c:\users\your_name\KLayout\lib\python3.11\.

    Kazzz-S

  • Hi @sekigawa,

    That is interesting, but it is kind of unintended ... I need to check myself why this is working. It may depend heavily on Python internals which is not good as it would change with other Python versions :(

    Thanks,

    Matthias

  • edited April 17

    Hello @Matthias,

    Oops, it's my mistake. My above description was incorrect. Sorry about that.
    I placed pylnk3.py in the system's Python library, as shown below.

    I assumed pylnk3.py needed to be treated as a part of the system's Python.

    I moved pylnk3.py to c:\users\your_name\KLayout\python ($HOME/.klayout/python/ in the Linux|Mac env.).
    Then, it still works as you intended.

    Thank you.
    Kazzz-S

  • Ah, very good. That is what I was expecting! :)

    Thanks for this confirmation.

    Matthias

Sign In or Register to comment.