How to Zoom&Move to a coordinates Using Python

As the question above, how to Zoom to a specific scale and Move to a (x,y) coordinates position using the Macro development?
Sorry for being such a freshman in KLayout

Comments

  • Hi, @EugeneZlenko,A further question: how to save the current DBox's layout View as image(Only the content inside the DBox in the current layout view)

  • @Matthias Thanks! Another question, Can macro inside the klayout use pickle or json? I tried to use 'klayout -z -r my_script.py args', and a json file path is in the args,which I wrote a json.load(json_file) in my_script, but it shows "ERROR: Stream has unknown format",Are there some intrisic problem or just my code error?

  • @kevin No, KLayout is not a Python interpreter and the command line belongs to it :)

    But you can define variables from the command line which you can access inside your script, e.g.

    $ klayout ... -r script.py -rd myvar=value
    
    in script.py:
    
    # "myvar" is a str("value")
    print(myvar)
    

    You can use "-rd" more than once to define multiple variables.

    Matthias

  • @Matthias Thanks!I tried ur suggestions and it works with some my-defined vars.
    Furthermore, I tried to use a variable like 'filepath=/home/myhome/sometxt.txt'.And in my klayout macro, There are codes read from such file stream.
    But I got an error: Unknown Stream Format.

    I tried pickle,json and plain txt, returned same error.
    How could I solve this problem? Can my macro read from such local files via any way?

  • What do you mean by "in my klayout macro, There are codes read from such file stream"? Please show some code which tells me what you are doing.

    Matthias

  • My code is:


    #load specific layout file win=pa.Application.instance().main_window() win.load_layout(GDS_FILE,0) view=win.current_view() #load another file f=json.load(open(FILE,'r'))

    and I use the shell script like"
    klayout -z -r myscript.lym -rd GDS_FILE=/home/myhome/mygds.gds FILE=/home/myhome/myfile.json
    "

    the problem is that:

    It always read only one parameter, and it shows Stream Unknown Format error when I tried to Read the Json.

    By the Way, What should I do if I want my python anaconda environment path included in the klayout python interpreter path? the Json/pickle file I used is just an alternative way to pandas ,which is not included in the native klayout python macro interpreter.

  • "Stream Unknown Format" is thrown by "win.load_layout(...)" if the file cannot be identified as a valid input file format (DXF, CIF, GDS, OASIS, ..). But this error should never be thrown by "js.load" or "open". Please check if "json" is not used as a variable name elsewhere or "GDS_FILE" for some reason maybe does not contain the path to the GDS file.

    Regarding Anaconda: if you're on Windows, forget this. On Linux, KLayout shares the libs with the system Python, so you can use "pip" to install packages which become available for KLayout too. But on Windows there are manifold compilers and runtimes and they are all incompatible, so KLayout comes with it's own brand of Python. This one is taken from MSYS2 which is mingw/cygwin based and not compatible with Anaconda. So you cannot import Anaconda modules.

    You can try using the Python "klayout" module available on PyPI (pip install klayout in Anaconda), but that offers a subset of KLayout's features. This will then make KLayout's database features available to Anaconda.

    Another option is to find a maintainer for some KLayout package for Anaconda, so KLayout becomes available in the conda ecosystem.

    Matthias

Sign In or Register to comment.